fix most of the clippy linter warnings

This commit is contained in:
Henrik Friedrichsen
2019-04-23 22:28:05 +02:00
parent fe3470479c
commit 18c2f6466a
6 changed files with 30 additions and 28 deletions

View File

@@ -51,7 +51,7 @@ pub fn create_credentials(path: &Path) -> Result<RespotCredentials, String> {
})); }));
s.quit(); s.quit();
}) })
.button("Quit", |s| s.quit()); .button("Quit", Cursive::quit);
s.pop_layer(); s.pop_layer();
s.add_layer(login_view); s.add_layer(login_view);
}) })
@@ -64,7 +64,7 @@ pub fn create_credentials(path: &Path) -> Result<RespotCredentials, String> {
// not a dialog to let people copy & paste the URL // not a dialog to let people copy & paste the URL
let url_notice = TextView::new(format!("Browse to {}", &urls["login_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) let login_view = LinearLayout::new(cursive::direction::Orientation::Vertical)
.child(url_notice) .child(url_notice)
@@ -75,7 +75,7 @@ pub fn create_credentials(path: &Path) -> Result<RespotCredentials, String> {
s.pop_layer(); s.pop_layer();
s.add_layer(login_view) s.add_layer(login_view)
}) })
.button("Quit", |s| s.quit()); .button("Quit", Cursive::quit);
login_cursive.add_layer(info_view); login_cursive.add_layer(info_view);
login_cursive.run(); login_cursive.run();

View File

@@ -248,7 +248,11 @@ impl CommandManager {
} }
pub fn handle(&self, s: &mut Cursive, cmd: String) { pub fn handle(&self, s: &mut Cursive, cmd: String) {
let components: Vec<String> = cmd.trim().split(' ').map(|s| s.to_string()).collect(); let components: Vec<String> = cmd
.trim()
.split(' ')
.map(std::string::ToString::to_string)
.collect();
let cmd = self.handle_aliases(&components[0]); let cmd = self.handle_aliases(&components[0]);
let args = components[1..].to_vec(); let args = components[1..].to_vec();

View File

@@ -354,7 +354,7 @@ impl Library {
let mut store = self.artists.write().unwrap(); let mut store = self.artists.write().unwrap();
for artist in artists.iter_mut() { 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 { if let Some(i) = pos {
store[i].is_followed = true; store[i].is_followed = true;
continue; 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(); let mut artists = self.artists.write().unwrap();
if !artists.iter().any(|a| &a.id == id) { if !artists.iter().any(|a| a.id == id) {
let mut artist = Artist::new(id.clone(), name.clone()); let mut artist = Artist::new(id.to_string(), name.to_string());
artist.tracks = Some(Vec::new()); artist.tracks = Some(Vec::new());
artists.push(artist); artists.push(artist);
} }
@@ -402,7 +402,7 @@ impl Library {
.items .items
.iter() .iter()
.enumerate() .enumerate()
.any(|(i, a)| &a.album.id != &store[i].id) .any(|(i, a)| a.album.id != store[i].id)
{ {
return; return;
} }
@@ -446,7 +446,7 @@ impl Library {
.items .items
.iter() .iter()
.enumerate() .enumerate()
.any(|(i, t)| &t.track.id != &store[i].id) .any(|(i, t)| t.track.id != store[i].id)
{ {
return; return;
} }
@@ -539,14 +539,13 @@ impl Library {
return; return;
} }
if api { if api
if self && self
.spotify .spotify
.current_user_saved_tracks_add(tracks.iter().map(|t| t.id.clone()).collect()) .current_user_saved_tracks_add(tracks.iter().map(|t| t.id.clone()).collect())
.is_none() .is_none()
{ {
return; return;
}
} }
{ {
@@ -573,14 +572,13 @@ impl Library {
return; return;
} }
if api { if api
if self && self
.spotify .spotify
.current_user_saved_tracks_delete(tracks.iter().map(|t| t.id.clone()).collect()) .current_user_saved_tracks_delete(tracks.iter().map(|t| t.id.clone()).collect())
.is_none() .is_none()
{ {
return; return;
}
} }
{ {

View File

@@ -43,7 +43,7 @@ use events::{Event, EventManager};
use track::Track; use track::Track;
enum WorkerCommand { enum WorkerCommand {
Load(Track), Load(Box<Track>),
Play, Play,
Pause, Pause,
Stop, Stop,
@@ -585,7 +585,7 @@ impl Spotify {
pub fn load(&self, track: &Track) { pub fn load(&self, track: &Track) {
info!("loading track: {:?}", track); info!("loading track: {:?}", track);
self.channel self.channel
.unbounded_send(WorkerCommand::Load(track.clone())) .unbounded_send(WorkerCommand::Load(Box::new(track.clone())))
.unwrap(); .unwrap();
} }

View File

@@ -125,7 +125,7 @@ impl Layout {
} }
fn get_current_screen(&self) -> Option<&Screen> { fn get_current_screen(&self) -> Option<&Screen> {
if self.stack.len() > 0 { if !self.stack.is_empty() {
return self.stack.last(); return self.stack.last();
} }
@@ -137,7 +137,7 @@ impl Layout {
} }
fn get_current_screen_mut(&mut self) -> Option<&mut Screen> { 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(); return self.stack.last_mut();
} }
@@ -155,7 +155,7 @@ impl View for Layout {
let cmdline_visible = self.cmdline.get_content().len() > 0; let cmdline_visible = self.cmdline.get_content().len() > 0;
let mut cmdline_height = if cmdline_visible { 1 } else { 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; cmdline_height += 1;
} }
@@ -165,7 +165,7 @@ impl View for Layout {
let offset = HAlign::Center.get_offset(screen.title.width(), printer.size.x); let offset = HAlign::Center.get_offset(screen.title.width(), printer.size.x);
printer.print((offset, 0), &screen.title); printer.print((offset, 0), &screen.title);
if self.stack.len() > 0 { if !self.stack.is_empty() {
printer.print((1, 0), "<"); printer.print((1, 0), "<");
} }
}); });
@@ -215,7 +215,7 @@ impl View for Layout {
let cmdline_visible = self.cmdline.get_content().len() > 0; let cmdline_visible = self.cmdline.get_content().len() > 0;
let mut cmdline_height = if cmdline_visible { 1 } else { 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; cmdline_height += 1;
} }

View File

@@ -354,7 +354,7 @@ impl<I: ListItem + Clone> ViewExt for ListView<I> {
if let Some(item) = content.get_mut(self.selected) { if let Some(item) = content.get_mut(self.selected) {
let queue = self.queue.clone(); let queue = self.queue.clone();
let library = self.library.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 arg == "album" {
if let Some(album) = item.album(queue.clone()) { if let Some(album) = item.album(queue.clone()) {