diff --git a/src/authentication.rs b/src/authentication.rs index 4e44ece..0b33930 100644 --- a/src/authentication.rs +++ b/src/authentication.rs @@ -51,7 +51,7 @@ pub fn create_credentials(path: &Path) -> Result { })); s.quit(); }) - .button("Quit", |s| s.quit()); + .button("Quit", Cursive::quit); s.pop_layer(); s.add_layer(login_view); }) @@ -64,7 +64,7 @@ pub fn create_credentials(path: &Path) -> Result { // not a dialog to let people copy & paste the URL let url_notice = TextView::new(format!("Browse to {}", &urls["login_url"])); - let controls = Button::new("Quit", |s| s.quit()); + let controls = Button::new("Quit", Cursive::quit); let login_view = LinearLayout::new(cursive::direction::Orientation::Vertical) .child(url_notice) @@ -75,7 +75,7 @@ pub fn create_credentials(path: &Path) -> Result { s.pop_layer(); s.add_layer(login_view) }) - .button("Quit", |s| s.quit()); + .button("Quit", Cursive::quit); login_cursive.add_layer(info_view); login_cursive.run(); diff --git a/src/commands.rs b/src/commands.rs index 26b878c..0f94dd2 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -248,7 +248,11 @@ impl CommandManager { } pub fn handle(&self, s: &mut Cursive, cmd: String) { - let components: Vec = cmd.trim().split(' ').map(|s| s.to_string()).collect(); + let components: Vec = cmd + .trim() + .split(' ') + .map(std::string::ToString::to_string) + .collect(); let cmd = self.handle_aliases(&components[0]); let args = components[1..].to_vec(); diff --git a/src/library.rs b/src/library.rs index 97aee8e..859edd1 100644 --- a/src/library.rs +++ b/src/library.rs @@ -354,7 +354,7 @@ impl Library { let mut store = self.artists.write().unwrap(); for artist in artists.iter_mut() { - let pos = store.iter().position(|a| &a.id == &artist.id); + let pos = store.iter().position(|a| a.id == artist.id); if let Some(i) = pos { store[i].is_followed = true; continue; @@ -366,11 +366,11 @@ impl Library { } } - fn insert_artist(&self, id: &String, name: &String) { + fn insert_artist(&self, id: &str, name: &str) { let mut artists = self.artists.write().unwrap(); - if !artists.iter().any(|a| &a.id == id) { - let mut artist = Artist::new(id.clone(), name.clone()); + if !artists.iter().any(|a| a.id == id) { + let mut artist = Artist::new(id.to_string(), name.to_string()); artist.tracks = Some(Vec::new()); artists.push(artist); } @@ -402,7 +402,7 @@ impl Library { .items .iter() .enumerate() - .any(|(i, a)| &a.album.id != &store[i].id) + .any(|(i, a)| a.album.id != store[i].id) { return; } @@ -446,7 +446,7 @@ impl Library { .items .iter() .enumerate() - .any(|(i, t)| &t.track.id != &store[i].id) + .any(|(i, t)| t.track.id != store[i].id) { return; } @@ -539,14 +539,13 @@ impl Library { return; } - if api { - if self + if api + && self .spotify .current_user_saved_tracks_add(tracks.iter().map(|t| t.id.clone()).collect()) .is_none() - { - return; - } + { + return; } { @@ -573,14 +572,13 @@ impl Library { return; } - if api { - if self + if api + && self .spotify .current_user_saved_tracks_delete(tracks.iter().map(|t| t.id.clone()).collect()) .is_none() - { - return; - } + { + return; } { diff --git a/src/spotify.rs b/src/spotify.rs index ae9c703..c5e0722 100644 --- a/src/spotify.rs +++ b/src/spotify.rs @@ -43,7 +43,7 @@ use events::{Event, EventManager}; use track::Track; enum WorkerCommand { - Load(Track), + Load(Box), Play, Pause, Stop, @@ -585,7 +585,7 @@ impl Spotify { pub fn load(&self, track: &Track) { info!("loading track: {:?}", track); self.channel - .unbounded_send(WorkerCommand::Load(track.clone())) + .unbounded_send(WorkerCommand::Load(Box::new(track.clone()))) .unwrap(); } diff --git a/src/ui/layout.rs b/src/ui/layout.rs index b6d1671..849d534 100644 --- a/src/ui/layout.rs +++ b/src/ui/layout.rs @@ -125,7 +125,7 @@ impl Layout { } fn get_current_screen(&self) -> Option<&Screen> { - if self.stack.len() > 0 { + if !self.stack.is_empty() { return self.stack.last(); } @@ -137,7 +137,7 @@ impl Layout { } fn get_current_screen_mut(&mut self) -> Option<&mut Screen> { - if self.stack.len() > 0 { + if !self.stack.is_empty() { return self.stack.last_mut(); } @@ -155,7 +155,7 @@ impl View for Layout { let cmdline_visible = self.cmdline.get_content().len() > 0; let mut cmdline_height = if cmdline_visible { 1 } else { 0 }; - if result.as_ref().map(|o| o.is_some()).unwrap_or(true) { + if result.as_ref().map(Option::is_some).unwrap_or(true) { cmdline_height += 1; } @@ -165,7 +165,7 @@ impl View for Layout { let offset = HAlign::Center.get_offset(screen.title.width(), printer.size.x); printer.print((offset, 0), &screen.title); - if self.stack.len() > 0 { + if !self.stack.is_empty() { printer.print((1, 0), "<"); } }); @@ -215,7 +215,7 @@ impl View for Layout { let cmdline_visible = self.cmdline.get_content().len() > 0; let mut cmdline_height = if cmdline_visible { 1 } else { 0 }; - if result.as_ref().map(|o| o.is_some()).unwrap_or(true) { + if result.as_ref().map(Option::is_some).unwrap_or(true) { cmdline_height += 1; } diff --git a/src/ui/listview.rs b/src/ui/listview.rs index 560c200..acb5566 100644 --- a/src/ui/listview.rs +++ b/src/ui/listview.rs @@ -354,7 +354,7 @@ impl ViewExt for ListView { if let Some(item) = content.get_mut(self.selected) { let queue = self.queue.clone(); let library = self.library.clone(); - let arg = args.get(0).map(|s| s.clone()).unwrap_or_default(); + let arg = args.get(0).cloned().unwrap_or_default(); if arg == "album" { if let Some(album) = item.album(queue.clone()) {