refactor: fix some clippy lints

cargo clippy --no-deps -- --warn clippy::nursery --warn clippy::pedantic
This commit is contained in:
electria 2026-11-03 12:31:39 -08:00
commit c8fd43fedd
Signed by: electria
SSH key fingerprint: SHA256:8LlB3ucPbBHqozqkhsNbaV5oG3SlzzqUj8FZDL6IPQs
2 changed files with 16 additions and 14 deletions

View file

@ -7,7 +7,7 @@ pub enum MaybeImage {
Unloaded,
#[allow(dead_code)]
/// should be abort_on_drop,
/// should be `abort_on_drop`,
/// so that it will abort, for instance,
/// when it's set back to `Self::Unloaded`
Loading(task::Handle),
@ -15,9 +15,9 @@ pub enum MaybeImage {
Loaded(widget::image::Handle),
}
impl MaybeImage {
pub fn handle(&self) -> Option<&widget::image::Handle> {
pub const fn handle(&self) -> Option<&widget::image::Handle> {
match self {
Self::Loaded(h) => Some(&h),
Self::Loaded(h) => Some(h),
_ => None,
}
}

View file

@ -103,15 +103,15 @@ impl State {
}
}
Message::ImageLoaded(result) => {
self.error = result.as_ref().err().map(|e| e.to_string());
self.error = result.as_ref().err().map(ToString::to_string);
if let Ok((path, handle)) = result {
let entry = self.images.entry(path).or_default();
if matches!(entry, MaybeImage::Loaded(_)) {
self.error = Some("tried to load already-loaded image!".into())
self.error = Some("tried to load already-loaded image!".into());
} else {
*entry = MaybeImage::Loaded(handle)
*entry = MaybeImage::Loaded(handle);
}
}
}
@ -141,7 +141,7 @@ impl State {
}
Message::FocusNext => return widget::operation::focus_next(),
Message::FocusPrevious => return widget::operation::focus_next(),
Message::FocusPrevious => return widget::operation::focus_previous(),
Message::PickPath => {
return Task::perform(
@ -233,16 +233,18 @@ impl State {
keyboard::Key::Character("j")
| keyboard::Key::Named(
keyboard::key::Named::ArrowDown | keyboard::key::Named::PageDown,
) => Some(Message::ScrollBy(match modifiers.shift() {
false => 100.,
true => 500.,
) => Some(Message::ScrollBy(if modifiers.shift() {
500.
} else {
100.
})),
keyboard::Key::Character("k")
| keyboard::Key::Named(
keyboard::key::Named::ArrowUp | keyboard::key::Named::PageUp,
) => Some(Message::ScrollBy(match modifiers.shift() {
false => -100.,
true => -500.,
) => Some(Message::ScrollBy(if modifiers.shift() {
-500.
} else {
-100.
})),
keyboard::Key::Character("=" | "+") => Some(Message::IncreaseColumns),
@ -275,7 +277,7 @@ impl State {
.filter_map(|r| {
r.inspect_err(|e| eprintln!("{e}"))
.ok()
.map(|entry| entry.into_path())
.map(ignore::DirEntry::into_path)
})
.filter(|path| path.is_file())
.map(|path| (path, MaybeImage::Unloaded))