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>) {
(
DelyriumApp(Model::DEFAULT),
Self(Model::DEFAULT),
Command::none(),
)
}

View File

@ -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<Message, (&Controls, Theme)> {
pub fn view_progress(&mut self, theme: Theme) -> Canvas<Message, (&Self, Theme)> {
Canvas::new((&*self, theme))
.width(Length::Units(50))
.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()
.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);

View File

@ -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,

View File

@ -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,

View File

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

View File

@ -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<u8> {
pub fn dominant_color(&self) -> Rgb<u8> {
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]
}
}

View File

@ -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
/// <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;

View File

@ -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<u8>) -> Color {
fn img_color_to_iced(color: Rgb<u8>) -> Color {
Color {
r: color[0] as f32 / 255.,
g: color[1] as f32 / 255.,