From 5dd4841e5506db9c86178c7b7c9bd6b08c02f22a Mon Sep 17 00:00:00 2001 From: Emi Simpson Date: Sat, 8 Jan 2022 10:28:42 -0500 Subject: [PATCH] And clippy lints too --- src/app.rs | 3 ++- src/editor.rs | 4 ++-- src/file_select.rs | 14 +++----------- src/load_song.rs | 3 ++- src/lyrics.rs | 15 +++++++-------- src/palette.rs | 2 +- src/player.rs | 18 +++++++++--------- 7 files changed, 26 insertions(+), 33 deletions(-) diff --git a/src/app.rs b/src/app.rs index 84300c8..35f1a6b 100644 --- a/src/app.rs +++ b/src/app.rs @@ -69,6 +69,7 @@ impl Application for DelyriumApp { }, Message::PasteSent => { if let Some(lyrics) = self.lyrics_component.as_mut() { + #[allow(clippy::or_fun_call)] // This is a const let clip_text = clipboard.read().unwrap_or(String::new()); let clip_pasted_len = clip_text.chars() .filter(|c| *c != '\r' && *c != '\n') @@ -138,7 +139,7 @@ impl Application for DelyriumApp { ( keyboard::KeyCode::V, keyboard::Modifiers { control, .. } - ) if control == true => { + ) if control => { Some(Message::PasteSent) } _ => { None } diff --git a/src/editor.rs b/src/editor.rs index 5a985c0..d40bc44 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -36,9 +36,9 @@ impl Editor { let theme = cover.as_ref() .map(|cover| { Theme::from_palette( - Palette::generate(&cover) + Palette::generate(cover) ) - }).unwrap_or_else(|| Theme::default()); + }).unwrap_or_else(Theme::default); let cover = cover.expect("TODO"); diff --git a/src/file_select.rs b/src/file_select.rs index d58ca27..7907d73 100644 --- a/src/file_select.rs +++ b/src/file_select.rs @@ -28,6 +28,7 @@ const COLORS: [Color; 6] = [ Color { r: 0., g: 0., b: 1., a: 1. }, Color { r: 1., g: 0., b: 1., a: 1. }, ];*/ +#[allow(clippy::eq_op)] const COLORS: [Color; 6] = [ Color { r: 255./255., g: 129./255., b: 126./255., a: 1. }, Color { r: 239./255., g: 190./255., b: 125./255., a: 1. }, @@ -44,7 +45,7 @@ const FONT_MR_PIXEL: Font = Font::External { bytes: include_bytes!("../fonts/mister-pixel/mister-pixel.otf"), }; -#[derive(Clone, Copy, Debug, Eq, PartialEq)] +#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] pub struct FileSelector { tick: usize, } @@ -62,17 +63,9 @@ impl FileSelector { } } -impl Default for FileSelector { - fn default() -> Self { - FileSelector { - tick: 0, - } - } -} - impl Program for FileSelector { fn draw(&self, bounds: Rectangle, _cursor: Cursor) -> Vec { - let offset_per_index = MAX_TICKS / &COLORS.len(); + let offset_per_index = MAX_TICKS / COLORS.len(); const TEXT_RECT_W: f32 = 350.; const TEXT_RECT_H: f32 = 50.; @@ -130,7 +123,6 @@ impl Program for FileSelector { bounds.x + bounds.width * 0.5, bounds.y + bounds.height * 0.5, ), - ..Default::default() } ); diff --git a/src/load_song.rs b/src/load_song.rs index 19f750a..1091cc9 100644 --- a/src/load_song.rs +++ b/src/load_song.rs @@ -39,11 +39,12 @@ pub fn load_song(path: &Path) -> Result { } pub fn extract_cover(format: &mut dyn FormatReader) -> Option{ + #[allow(clippy::zero_prefixed_literal)] format.metadata() .current() .into_iter() // Replace this whole closure with MetadataRef::usage once we update - .flat_map(|meta| meta.visuals().iter().map(|v|(v.data.clone(), v.usage.clone())).collect::>()) + .flat_map(|meta| meta.visuals().iter().map(|v|(v.data.clone(), v.usage)).collect::>()) .filter_map(|(data, usage)| image::load_from_memory(&data).ok().map(|img| (usage, img))) .max_by_key(|(usage, _)| usage.map(|usage| match usage { diff --git a/src/lyrics.rs b/src/lyrics.rs index 64e82de..7b2675b 100644 --- a/src/lyrics.rs +++ b/src/lyrics.rs @@ -22,7 +22,7 @@ pub enum LyricEvent { } impl LyricEvent { - fn to_msg(self, line_no: usize) -> Message { + fn into_msg(self, line_no: usize) -> Message { Message::LyricEvent { kind: self, line_no, @@ -116,8 +116,7 @@ impl Lyrics { self.lines .iter_mut() .enumerate() - .filter(|(_, l)| l.is_selected()) - .next() + .find(|(_, l)| l.is_selected()) .expect("no line currently selected") } @@ -180,24 +179,24 @@ impl Lyric { &mut self.timestamp_state, "", &self.timestamp_raw, - move|new_value| LyricEvent::TimestampChanged(new_value).to_msg(line_no), + move|new_value| LyricEvent::TimestampChanged(new_value).into_msg(line_no), ) .style(theme) .size(size - 5) .width(Length::Units(97)) - .on_submit(LyricEvent::LineAdvanced.to_msg(line_no)) + .on_submit(LyricEvent::LineAdvanced.into_msg(line_no)) .into(); let text_input = TextInput::new( &mut self.main_state, placeholder, &self.value, - move|new_value| LyricEvent::LyricChanged(new_value).to_msg(line_no), + move|new_value| LyricEvent::LyricChanged(new_value).into_msg(line_no), ) .style(theme) .size(size) .width(Length::Fill) - .on_submit(LyricEvent::LineAdvanced.to_msg(line_no)) + .on_submit(LyricEvent::LineAdvanced.into_msg(line_no)) .into(); let l_bracket = Text::new("[") @@ -303,7 +302,7 @@ impl Lyric { while digit_counts[section] > MIN_DIGIT_COUNTS[section] && if section == 2 { - raw.chars().next_back().unwrap() == '0' + raw.ends_with('0') } else { raw.chars().nth(i).unwrap() == '0' } diff --git a/src/palette.rs b/src/palette.rs index 06fd710..1fb2cb4 100644 --- a/src/palette.rs +++ b/src/palette.rs @@ -89,6 +89,6 @@ impl Palette { .unwrap() .0; - return &self.raw_colors[max_index]; + &self.raw_colors[max_index] } } diff --git a/src/player.rs b/src/player.rs index 3b30b85..553a216 100644 --- a/src/player.rs +++ b/src/player.rs @@ -37,7 +37,7 @@ impl Player { pub fn new(song: Box) -> Result { let song = Decoder::new_from_format_reader(song) - .map_err(PlayerError::DecoderError)? + .map_err(PlayerError::Decoder)? .buffered(); let duration = Duration::from_secs(150); @@ -74,10 +74,10 @@ impl Player { Some(result) // We'll report this error }) .transpose() - .map_err(PlayerError::StreamError)? + .map_err(PlayerError::Stream)? .map(|(stream, handle)| Sink::try_new(&handle).map(|sink| (sink, stream))) .transpose() - .map_err(PlayerError::PlayError)?; + .map_err(PlayerError::Play)?; Ok(self.sink.as_ref().map(|(s, _)| s)) } @@ -274,17 +274,17 @@ impl Player { #[derive(Debug)] pub enum PlayerError { - DecoderError(rodio::decoder::DecoderError), - PlayError(rodio::PlayError), - StreamError(rodio::StreamError), + Decoder(rodio::decoder::DecoderError), + Play(rodio::PlayError), + Stream(rodio::StreamError), } impl fmt::Display for PlayerError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - Self::DecoderError(e) => write!(f, "Could not decode the provided song: {}", e), - Self::PlayError(e) => write!(f, "Problem playing to the audio output: {}", e), - Self::StreamError(e) => write!(f, "Problem connecting to the audio output: {}", e), + Self::Decoder(e) => write!(f, "Could not decode the provided song: {}", e), + Self::Play(e) => write!(f, "Problem playing to the audio output: {}", e), + Self::Stream(e) => write!(f, "Problem connecting to the audio output: {}", e), } } }