Add a whole bunch more clippy lints

This commit is contained in:
Emi Simpson 2022-01-26 18:42:31 -05:00
parent 29d36a8010
commit 436403d129
Signed by: Emi
GPG Key ID: A12F2C2FFDC3D847
9 changed files with 52 additions and 53 deletions

View File

@ -40,7 +40,7 @@ impl Application for DelyriumApp {
fn new(_: Self::Flags) -> (Self, Command<Message>) { fn new(_: Self::Flags) -> (Self, Command<Message>) {
( (
DelyriumApp(Model::DEFAULT), Self(Model::DEFAULT),
Command::none(), Command::none(),
) )
} }

View File

@ -49,7 +49,7 @@ impl Controls {
); );
( (
Controls(NoError { Self(NoError {
has_device: player.has_output_device(), has_device: player.has_output_device(),
player, player,
}), }),
@ -57,12 +57,12 @@ impl Controls {
) )
}, },
Err(e) => { Err(e) => {
(Controls(Error(e)), Command::none()) (Self(Error(e)), Command::none())
} }
} }
} }
pub fn view_progress(&mut self, theme: Theme) -> Canvas<Message, (&Controls, Theme)> { pub fn view_progress(&mut self, theme: Theme) -> Canvas<Message, (&Self, Theme)> {
Canvas::new((&*self, theme)) Canvas::new((&*self, theme))
.width(Length::Units(50)) .width(Length::Units(50))
.height(Length::Fill) .height(Length::Fill)

View File

@ -58,7 +58,7 @@ pub fn view_lyrics<'a>(lyrics: &'a mut [Lyric], scroll_state: &'a mut scrollable
let scroller = lyrics.iter_mut() let scroller = lyrics.iter_mut()
.enumerate() .enumerate()
.map(|(i, l)| view_lyric(l, is_sole_line, i, theme)) .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) .push(spacers.1)
.width(Length::Fill) .width(Length::Fill)
.align_items(Alignment::Center); .align_items(Alignment::Center);

View File

@ -30,12 +30,14 @@ pub fn load_song(path: &Path) -> Result<(File, ProbeResult), LoadError> {
let ext_hint = path.extension() let ext_hint = path.extension()
.and_then(OsStr::to_str) .and_then(OsStr::to_str)
.map(|ext| { .map_or_else(
let mut h = Hint::new(); Hint::new,
h.with_extension(ext); |ext| {
h let mut h = Hint::new();
}) h.with_extension(ext);
.unwrap_or_else(Hint::new); h
}
);
probe.format( probe.format(
&ext_hint, &ext_hint,

View File

@ -67,11 +67,13 @@ impl Editing {
let cover = extract_cover(fr.as_mut()); let cover = extract_cover(fr.as_mut());
let theme = cover.as_ref() let theme = cover.as_ref()
.map(|cover| { .map_or_else(
Theme::from_palette( Theme::default,
Palette::generate(cover) |cover|
) Theme::from_palette(
}).unwrap_or_else(Theme::default); &Palette::generate(cover)
),
);
let cover = cover.map(|cover| { let cover = cover.map(|cover| {
#[cfg(not(debug_assertions))] #[cfg(not(debug_assertions))]
@ -108,22 +110,19 @@ impl Editing {
let mut command = None; let mut command = None;
match message { match message {
Message::LyricEvent { line_no, kind: LyricEvent::LyricChanged(newval) } => { 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) } => { 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 } => { Message::LyricEvent { line_no, kind: LyricEvent::LineAdvanced } => {
self.advance_line(line_no, self.controls.position()) self.advance_line(line_no, self.controls.position())
}, },
Message::PasteSent => { Message::PasteSent => {
command = Some(clipboard::read(|clip| command = Some(clipboard::read(|clip| clip.map_or(
if let Some(clip) = clip { Message::Null,
Message::PasteRead(clip) Message::PasteRead,
} else { )));
Message::Null
}
));
}, },
Message::PasteRead(clip_text) => { Message::PasteRead(clip_text) => {
let clip_pasted_len = clip_text.chars() let clip_pasted_len = clip_text.chars()
@ -131,11 +130,11 @@ impl Editing {
.count(); .count();
if let Some(line) = self.current_line_mut() { if let Some(line) = self.current_line_mut() {
line.value.truncate(line.value.len() - clip_pasted_len); line.value.truncate(line.value.len() - clip_pasted_len);
self.insert_text(clip_text); self.insert_text(&clip_text);
} }
}, },
Message::ControlsEvent(e) => { Message::ControlsEvent(e) => {
self.controls.handle_event(e) self.controls.handle_event(e);
}, },
Message::Null | Message::Null |
Message::PromptForFile | Message::PromptForFile |
@ -189,7 +188,7 @@ impl Editing {
self.controls.is_playing() 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() let mut pieces = text.trim_end()
.split('\n') .split('\n')
@ -221,7 +220,7 @@ impl Lyric {
} }
pub fn new_with_value(val: String) -> Self { pub fn new_with_value(val: String) -> Self {
Lyric { Self {
main_state: text_input::State::new(), main_state: text_input::State::new(),
timestamp_state: text_input::State::new(), timestamp_state: text_input::State::new(),
timestamp: Duration::ZERO, timestamp: Duration::ZERO,

View File

@ -19,7 +19,7 @@ pub enum Model {
const MAX_TICKS: usize = 900; const MAX_TICKS: usize = 900;
impl Model { 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<Message> { pub fn update(&mut self, message: Message) -> Command<Message> {
match self { match self {
@ -49,11 +49,10 @@ impl Model {
.set_title("Select a song") .set_title("Select a song")
.pick_file(); .pick_file();
let to_message = |handle: Option<FileHandle>| if let Some(h) = handle { let to_message = |handle: Option<FileHandle>| handle.map_or(
Message::FileOpened(h.path().to_owned()) Message::Null,
} else { |h| Message::FileOpened(h.path().to_owned()),
Message::Null );
};
Command::perform(show_dialog, to_message) Command::perform(show_dialog, to_message)
}, },

View File

@ -20,7 +20,7 @@ pub struct Palette {
impl Palette { impl Palette {
pub fn generate(img: &DynamicImage) -> Self { pub fn generate(img: &DynamicImage) -> Self {
let _thumb; let thumb;
// Scale the image down if it's too big // Scale the image down if it's too big
let thumb = if img.width() * img.height() > MAX_SIZE_PIXELS { 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_width = (ratio * RESIZE_TARGET_PIXELS).sqrt();
let new_height = RESIZE_TARGET_PIXELS / new_width; let new_height = RESIZE_TARGET_PIXELS / new_width;
_thumb = img.thumbnail(new_width as u32, new_height as u32); thumb = img.thumbnail(new_width as u32, new_height as u32);
&_thumb &thumb
} else { } else {
img img
}; };
@ -45,7 +45,7 @@ impl Palette {
.collect(); .collect();
// Generate histogram // Generate histogram
let histogram = exo_img.iter().cloned().collect(); let histogram = exo_img.iter().copied().collect();
// Generate raw palette // Generate raw palette
let colorspace = SimpleColorSpace::default(); let colorspace = SimpleColorSpace::default();
@ -81,7 +81,7 @@ impl Palette {
} }
} }
pub fn dominant_color(&self) -> &Rgb<u8> { pub fn dominant_color(&self) -> Rgb<u8> {
let max_index = self.color_frequencies let max_index = self.color_frequencies
.iter() .iter()
.enumerate() .enumerate()
@ -89,6 +89,6 @@ impl Palette {
.unwrap() .unwrap()
.0; .0;
&self.raw_colors[max_index] self.raw_colors[max_index]
} }
} }

View File

@ -42,7 +42,7 @@ impl Player {
let duration = Duration::from_secs(150); let duration = Duration::from_secs(150);
let mut player = Player { let mut player = Self {
sink: None, sink: None,
start_position: Duration::ZERO, start_position: Duration::ZERO,
playback_started: None, playback_started: None,
@ -172,8 +172,7 @@ impl Player {
let was_stopped = self.sink let was_stopped = self.sink
.as_mut() .as_mut()
.map(|(s, _)| s.is_paused() || s.empty()) .map_or(false, |(s, _)| s.is_paused() || s.empty());
.unwrap_or(false);
let song = self.song.clone(); let song = self.song.clone();
if let Some(sink) = self.try_set_sink()? { if let Some(sink) = self.try_set_sink()? {
@ -244,7 +243,7 @@ impl Player {
/// Technical Details: Currently, this involves decoding and inefficiently counting /// 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 /// the number of samples in the song. Hopefully, we'll be able to do this more
/// efficiently in the future, pending mostly on /// efficiently in the future, pending mostly on
/// https://github.com/RustAudio/rodio/issues/405 /// <https://github.com/RustAudio/rodio/issues/405>
pub fn compute_duration(&self) -> impl FnOnce() -> Duration { pub fn compute_duration(&self) -> impl FnOnce() -> Duration {
let sample_rate = self.song.sample_rate() as u64; let sample_rate = self.song.sample_rate() as u64;
let n_channels = self.song.channels() as u64; let n_channels = self.song.channels() as u64;

View File

@ -26,7 +26,7 @@ enum Subtype {
use Subtype::*; use Subtype::*;
impl Theme { 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 base_color = img_color_to_iced(palette.dominant_color());
let luma = relative_lum(base_color); let luma = relative_lum(base_color);
let text_color = if luma > 0.2 { let text_color = if luma > 0.2 {
@ -37,20 +37,20 @@ impl Theme {
} else { } else {
Color::WHITE Color::WHITE
}; };
Theme { Self {
subtype: Base, subtype: Base,
base_color, text_color, base_color, text_color,
} }
} }
pub fn reduced_text_color(&self) -> Color { pub const fn reduced_text_color(&self) -> Color {
Color { Color {
a: 0.7, a: 0.7,
..self.text_color ..self.text_color
} }
} }
pub fn active_lyric(&self, active: bool) -> Self { pub const fn active_lyric(&self, active: bool) -> Self {
if active { if active {
self.set_subtype(ActiveLyric) self.set_subtype(ActiveLyric)
} else { } else {
@ -58,8 +58,8 @@ impl Theme {
} }
} }
fn set_subtype(&self, subtype: Subtype) -> Self { const fn set_subtype(&self, subtype: Subtype) -> Self {
Theme { Self {
subtype, subtype,
..*self ..*self
} }
@ -68,7 +68,7 @@ impl Theme {
impl Default for Theme { impl Default for Theme {
fn default() -> Self { fn default() -> Self {
Theme { Self {
base_color: Color {r: 236. / 255., g: 63. / 255., b: 53. / 255., a: 1.}, 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.}, text_color: Color {r: 1., g: 1., b: 1., a: 1.},
subtype: Base, subtype: Base,
@ -120,7 +120,7 @@ impl text_input::StyleSheet for Theme {
} }
} }
fn img_color_to_iced(color: &Rgb<u8>) -> Color { fn img_color_to_iced(color: Rgb<u8>) -> Color {
Color { Color {
r: color[0] as f32 / 255., r: color[0] as f32 / 255.,
g: color[1] as f32 / 255., g: color[1] as f32 / 255.,