Clone map so that it multiple closures can use it and implement FnMut
authorJacob Casper <dev@jacobcasper.com>
Tue, 20 Oct 2020 02:35:23 +0000 (21:35 -0500)
committerJacob Casper <dev@jacobcasper.com>
Tue, 20 Oct 2020 02:35:23 +0000 (21:35 -0500)
src/main.rs

index 0a5eda3..da31c89 100644 (file)
@@ -24,6 +24,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
         Duration::from_millis(5000),
     );
 
+    let spotify_match_map = arc_locked_xset_map.clone();
     let _ = proxy.match_signal(
         move |pc: PropertiesPropertiesChanged, _: &Connection, _: &Message| {
             pc.changed_properties["Metadata"]
@@ -35,19 +36,17 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
                         let key_str = key.as_str()?;
                         let value = iter.next();
 
-                        let arc_locked_xset_map = Arc::clone(&arc_locked_xset_map);
-
                         match key_str {
                             "xesam:artist" => {
                                 // Variant holding a variant that should just be a Vec<&str> I
                                 // believe. This is _the recommended_ way to do this by the author.
                                 let inner_value = value?.as_iter()?.next()?.as_iter()?.next()?;
                                 let artist = inner_value.as_str()?;
-                                update_map(arc_locked_xset_map, "artist", artist);
+                                update_map(spotify_match_map.clone(), "artist", artist);
                             }
                             "xesam:title" => {
                                 let title = value?.as_iter()?.next()?.as_str()?;
-                                update_map(arc_locked_xset_map, "title", title);
+                                update_map(spotify_match_map.clone(), "title", title);
                             }
                             _ => (),
                         }