diff --git a/src/app.rs b/src/app.rs index 1207361..0fc06c9 100644 --- a/src/app.rs +++ b/src/app.rs @@ -40,7 +40,7 @@ impl Application for DelyriumApp { fn new(_: Self::Flags) -> (Self, Command) { ( - DelyriumApp(Model::DEFAULT), + Self(Model::DEFAULT), Command::none(), ) } diff --git a/src/controls.rs b/src/controls.rs index 7a6dc06..7d89b60 100644 --- a/src/controls.rs +++ b/src/controls.rs @@ -49,7 +49,7 @@ impl Controls { ); ( - Controls(NoError { + Self(NoError { has_device: player.has_output_device(), player, }), @@ -57,12 +57,12 @@ impl Controls { ) }, Err(e) => { - (Controls(Error(e)), Command::none()) + (Self(Error(e)), Command::none()) } } } - pub fn view_progress(&mut self, theme: Theme) -> Canvas { + pub fn view_progress(&mut self, theme: Theme) -> Canvas { Canvas::new((&*self, theme)) .width(Length::Units(50)) .height(Length::Fill) diff --git a/src/editor.rs b/src/editor.rs index 6bc0c0b..c7c8ad3 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -58,7 +58,7 @@ pub fn view_lyrics<'a>(lyrics: &'a mut [Lyric], scroll_state: &'a mut scrollable let scroller = lyrics.iter_mut() .enumerate() .map(|(i, l)| view_lyric(l, is_sole_line, i, theme)) - .fold(Scrollable::new(scroll_state).push(spacers.0), |s, l| s.push(l)) + .fold(Scrollable::new(scroll_state).push(spacers.0), Scrollable::push) .push(spacers.1) .width(Length::Fill) .align_items(Alignment::Center); diff --git a/src/load_song.rs b/src/load_song.rs index 73e60e2..db5db2b 100644 --- a/src/load_song.rs +++ b/src/load_song.rs @@ -30,12 +30,14 @@ pub fn load_song(path: &Path) -> Result<(File, ProbeResult), LoadError> { let ext_hint = path.extension() .and_then(OsStr::to_str) - .map(|ext| { - let mut h = Hint::new(); - h.with_extension(ext); - h - }) - .unwrap_or_else(Hint::new); + .map_or_else( + Hint::new, + |ext| { + let mut h = Hint::new(); + h.with_extension(ext); + h + } + ); probe.format( &ext_hint, diff --git a/src/model/editing.rs b/src/model/editing.rs index 8079006..7a4a351 100644 --- a/src/model/editing.rs +++ b/src/model/editing.rs @@ -67,11 +67,13 @@ impl Editing { let cover = extract_cover(fr.as_mut()); let theme = cover.as_ref() - .map(|cover| { - Theme::from_palette( - Palette::generate(cover) - ) - }).unwrap_or_else(Theme::default); + .map_or_else( + Theme::default, + |cover| + Theme::from_palette( + &Palette::generate(cover) + ), + ); let cover = cover.map(|cover| { #[cfg(not(debug_assertions))] @@ -108,22 +110,19 @@ impl Editing { let mut command = None; match message { Message::LyricEvent { line_no, kind: LyricEvent::LyricChanged(newval) } => { - self.lyrics[line_no].value = newval + self.lyrics[line_no].value = newval; }, Message::LyricEvent { line_no, kind: LyricEvent::TimestampChanged(newval) } => { - self.lyrics[line_no].timestamp_update(newval) + self.lyrics[line_no].timestamp_update(newval); }, Message::LyricEvent { line_no, kind: LyricEvent::LineAdvanced } => { self.advance_line(line_no, self.controls.position()) }, Message::PasteSent => { - command = Some(clipboard::read(|clip| - if let Some(clip) = clip { - Message::PasteRead(clip) - } else { - Message::Null - } - )); + command = Some(clipboard::read(|clip| clip.map_or( + Message::Null, + Message::PasteRead, + ))); }, Message::PasteRead(clip_text) => { let clip_pasted_len = clip_text.chars() @@ -131,11 +130,11 @@ impl Editing { .count(); if let Some(line) = self.current_line_mut() { line.value.truncate(line.value.len() - clip_pasted_len); - self.insert_text(clip_text); + self.insert_text(&clip_text); } }, Message::ControlsEvent(e) => { - self.controls.handle_event(e) + self.controls.handle_event(e); }, Message::Null | Message::PromptForFile | @@ -189,7 +188,7 @@ impl Editing { self.controls.is_playing() } - pub fn insert_text(&mut self, text: String) { + pub fn insert_text(&mut self, text: &str) { let mut pieces = text.trim_end() .split('\n') @@ -221,7 +220,7 @@ impl Lyric { } pub fn new_with_value(val: String) -> Self { - Lyric { + Self { main_state: text_input::State::new(), timestamp_state: text_input::State::new(), timestamp: Duration::ZERO, diff --git a/src/model/mod.rs b/src/model/mod.rs index 04f305d..04f9973 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -19,7 +19,7 @@ pub enum Model { const MAX_TICKS: usize = 900; impl Model { - pub const DEFAULT: Self = Model::FilePicker { tick: 0 }; + pub const DEFAULT: Self = Self::FilePicker { tick: 0 }; pub fn update(&mut self, message: Message) -> Command { match self { @@ -49,11 +49,10 @@ impl Model { .set_title("Select a song") .pick_file(); - let to_message = |handle: Option| if let Some(h) = handle { - Message::FileOpened(h.path().to_owned()) - } else { - Message::Null - }; + let to_message = |handle: Option| handle.map_or( + Message::Null, + |h| Message::FileOpened(h.path().to_owned()), + ); Command::perform(show_dialog, to_message) }, diff --git a/src/palette.rs b/src/palette.rs index 1fb2cb4..71329f2 100644 --- a/src/palette.rs +++ b/src/palette.rs @@ -20,7 +20,7 @@ pub struct Palette { impl Palette { pub fn generate(img: &DynamicImage) -> Self { - let _thumb; + let thumb; // Scale the image down if it's too big let thumb = if img.width() * img.height() > MAX_SIZE_PIXELS { @@ -31,8 +31,8 @@ impl Palette { let new_width = (ratio * RESIZE_TARGET_PIXELS).sqrt(); let new_height = RESIZE_TARGET_PIXELS / new_width; - _thumb = img.thumbnail(new_width as u32, new_height as u32); - &_thumb + thumb = img.thumbnail(new_width as u32, new_height as u32); + &thumb } else { img }; @@ -45,7 +45,7 @@ impl Palette { .collect(); // Generate histogram - let histogram = exo_img.iter().cloned().collect(); + let histogram = exo_img.iter().copied().collect(); // Generate raw palette let colorspace = SimpleColorSpace::default(); @@ -81,7 +81,7 @@ impl Palette { } } - pub fn dominant_color(&self) -> &Rgb { + pub fn dominant_color(&self) -> Rgb { let max_index = self.color_frequencies .iter() .enumerate() @@ -89,6 +89,6 @@ impl Palette { .unwrap() .0; - &self.raw_colors[max_index] + self.raw_colors[max_index] } } diff --git a/src/player.rs b/src/player.rs index aabb95f..4f9a560 100644 --- a/src/player.rs +++ b/src/player.rs @@ -42,7 +42,7 @@ impl Player { let duration = Duration::from_secs(150); - let mut player = Player { + let mut player = Self { sink: None, start_position: Duration::ZERO, playback_started: None, @@ -172,8 +172,7 @@ impl Player { let was_stopped = self.sink .as_mut() - .map(|(s, _)| s.is_paused() || s.empty()) - .unwrap_or(false); + .map_or(false, |(s, _)| s.is_paused() || s.empty()); let song = self.song.clone(); if let Some(sink) = self.try_set_sink()? { @@ -244,7 +243,7 @@ impl Player { /// Technical Details: Currently, this involves decoding and inefficiently counting /// the number of samples in the song. Hopefully, we'll be able to do this more /// efficiently in the future, pending mostly on - /// https://github.com/RustAudio/rodio/issues/405 + /// pub fn compute_duration(&self) -> impl FnOnce() -> Duration { let sample_rate = self.song.sample_rate() as u64; let n_channels = self.song.channels() as u64; diff --git a/src/styles.rs b/src/styles.rs index efd4171..349d7d6 100644 --- a/src/styles.rs +++ b/src/styles.rs @@ -26,7 +26,7 @@ enum Subtype { use Subtype::*; impl Theme { - pub fn from_palette(palette: Palette) -> Self { + pub fn from_palette(palette: &Palette) -> Self { let base_color = img_color_to_iced(palette.dominant_color()); let luma = relative_lum(base_color); let text_color = if luma > 0.2 { @@ -37,20 +37,20 @@ impl Theme { } else { Color::WHITE }; - Theme { + Self { subtype: Base, base_color, text_color, } } - pub fn reduced_text_color(&self) -> Color { + pub const fn reduced_text_color(&self) -> Color { Color { a: 0.7, ..self.text_color } } - pub fn active_lyric(&self, active: bool) -> Self { + pub const fn active_lyric(&self, active: bool) -> Self { if active { self.set_subtype(ActiveLyric) } else { @@ -58,8 +58,8 @@ impl Theme { } } - fn set_subtype(&self, subtype: Subtype) -> Self { - Theme { + const fn set_subtype(&self, subtype: Subtype) -> Self { + Self { subtype, ..*self } @@ -68,7 +68,7 @@ impl Theme { impl Default for Theme { fn default() -> Self { - Theme { + Self { base_color: Color {r: 236. / 255., g: 63. / 255., b: 53. / 255., a: 1.}, text_color: Color {r: 1., g: 1., b: 1., a: 1.}, subtype: Base, @@ -120,7 +120,7 @@ impl text_input::StyleSheet for Theme { } } -fn img_color_to_iced(color: &Rgb) -> Color { +fn img_color_to_iced(color: Rgb) -> Color { Color { r: color[0] as f32 / 255., g: color[1] as f32 / 255.,