From 46abd9dd7a6ab1152bd920fec5ba19744e83d186 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Fri, 26 Sep 2025 14:05:57 -0500 Subject: [PATCH] some clippy fixes --- src/core/images.rs | 2 +- src/core/presentations.rs | 2 +- src/core/videos.rs | 2 +- src/main.rs | 9 ++-- src/ui/image_editor.rs | 3 +- src/ui/library.rs | 75 ++++++++++++------------------ src/ui/presentation_editor.rs | 5 +- src/ui/presenter.rs | 17 +++---- src/ui/service.rs | 6 +-- src/ui/song_editor.rs | 4 +- src/ui/video_editor.rs | 3 +- src/ui/widgets/draggable/column.rs | 7 +-- src/ui/widgets/draggable/row.rs | 4 +- 13 files changed, 54 insertions(+), 85 deletions(-) diff --git a/src/core/images.rs b/src/core/images.rs index 9656f4e..fda63f4 100644 --- a/src/core/images.rs +++ b/src/core/images.rs @@ -211,7 +211,7 @@ pub async fn update_image_in_db( .map(std::string::ToString::to_string) .unwrap_or_default(); let mut db = db.detach(); - let id = image.id.clone(); + let id = image.id; if let Err(e) = query!("SELECT id FROM images where id = $1", id) .fetch_one(&mut db) .await diff --git a/src/core/presentations.rs b/src/core/presentations.rs index 246164b..4ada88e 100644 --- a/src/core/presentations.rs +++ b/src/core/presentations.rs @@ -318,7 +318,7 @@ pub async fn update_presentation_in_db( .unwrap_or_default(); let html = presentation.kind == PresKind::Html; let mut db = db.detach(); - let id = presentation.id.clone(); + let id = presentation.id; if let Err(e) = query!("SELECT id FROM presentations where id = $1", id) .fetch_one(&mut db) diff --git a/src/core/videos.rs b/src/core/videos.rs index 42e1c2b..dc97db6 100644 --- a/src/core/videos.rs +++ b/src/core/videos.rs @@ -246,7 +246,7 @@ pub async fn update_video_in_db( .map(std::string::ToString::to_string) .unwrap_or_default(); let mut db = db.detach(); - let id = video.id.clone(); + let id = video.id; if let Err(e) = query!("SELECT id FROM videos where id = $1", id) .fetch_one(&mut db) .await diff --git a/src/main.rs b/src/main.rs index e667b26..e2d9871 100644 --- a/src/main.rs +++ b/src/main.rs @@ -765,7 +765,7 @@ impl cosmic::Application for App { }) } song_editor::Action::UpdateSong(song) => { - if let Some(_) = &mut self.library { + if self.library.is_some() { self.update(Message::Library( library::Message::UpdateSong(song), )) @@ -786,7 +786,7 @@ impl cosmic::Application for App { }) } image_editor::Action::UpdateImage(image) => { - if let Some(_) = &mut self.library { + if self.library.is_some() { self.update(Message::Library( library::Message::UpdateImage(image), )) @@ -807,7 +807,7 @@ impl cosmic::Application for App { }) } video_editor::Action::UpdateVideo(video) => { - if let Some(_) = &mut self.library { + if self.library.is_some() { self.update(Message::Library( library::Message::UpdateVideo(video), )) @@ -1732,8 +1732,7 @@ where moved_item_overlay: Color::from( t.cosmic().primary.base, ) - .scale_alpha(0.2) - .into(), + .scale_alpha(0.2), ghost_border: Border { width: 1.0, color: t.cosmic().secondary.base.into(), diff --git a/src/ui/image_editor.rs b/src/ui/image_editor.rs index ba3eb03..878fe8e 100644 --- a/src/ui/image_editor.rs +++ b/src/ui/image_editor.rs @@ -73,8 +73,7 @@ impl ImageEditor { .image .as_ref() .map(|v| v.id) - .unwrap_or_default() - .clone(); + .unwrap_or_default(); let task = Task::perform( pick_image(), move |image_result| { diff --git a/src/ui/library.rs b/src/ui/library.rs index a9350c2..3a1921a 100644 --- a/src/ui/library.rs +++ b/src/ui/library.rs @@ -19,7 +19,7 @@ use cosmic::{ }, Element, Task, }; -use miette::{miette, IntoDiagnostic, Result}; +use miette::{IntoDiagnostic, Result}; use rapidfuzz::distance::levenshtein; use sqlx::{migrate, SqlitePool}; use tracing::{debug, error, warn}; @@ -156,13 +156,13 @@ impl<'a> Library { LibraryKind::Video => { return Action::Task(Task::perform( add_videos(), - |videos| Message::AddVideos(videos), + Message::AddVideos, )); } LibraryKind::Image => { return Action::Task(Task::perform( add_images(), - |images| Message::AddImages(images), + Message::AddImages, )); } LibraryKind::Presentation => { @@ -248,13 +248,12 @@ impl<'a> Library { let Some(first_item) = self .selected_items .as_ref() - .map(|items| { + .and_then(|items| { items .iter() .next() .map(|(_, index)| index) }) - .flatten() else { let Some(item) = item else { return Action::None; @@ -270,9 +269,9 @@ impl<'a> Library { self.selected_items = self .selected_items .clone() - .and_then(|mut items| { + .map(|mut items| { items.push((kind, id)); - Some(items) + items }); } } else if first_item > &index { @@ -280,9 +279,9 @@ impl<'a> Library { self.selected_items = self .selected_items .clone() - .and_then(|mut items| { + .map(|mut items| { items.push((kind, id)); - Some(items) + items }); } } @@ -908,25 +907,21 @@ impl<'a> Library { error!(?e); Task::none() } else { - let task = - Task::future(self.db.acquire()) + + Task::future(self.db.acquire()) .and_then(move |db| { Task::perform( songs::remove_from_db( db, song.id, ), |r| { - match r { - Err(e) => { - error!(?e) - } - _ => (), + if let Err(e) = r { + error!(?e) } Message::None }, ) - }); - task + }) } } else { Task::none() @@ -943,25 +938,21 @@ impl<'a> Library { error!(?e); Task::none() } else { - let task = - Task::future(self.db.acquire()) + + Task::future(self.db.acquire()) .and_then(move |db| { Task::perform( videos::remove_from_db( db, video.id, ), |r| { - match r { - Err(e) => { - error!(?e) - } - _ => (), + if let Err(e) = r { + error!(?e) } Message::None }, ) - }); - task + }) } } else { Task::none() @@ -978,25 +969,21 @@ impl<'a> Library { error!(?e); Task::none() } else { - let task = - Task::future(self.db.acquire()) + + Task::future(self.db.acquire()) .and_then(move |db| { Task::perform( images::remove_from_db( db, image.id, ), |r| { - match r { - Err(e) => { - error!(?e) - } - _ => (), + if let Err(e) = r { + error!(?e) } Message::None }, ) - }); - task + }) } } else { Task::none() @@ -1014,8 +1001,8 @@ impl<'a> Library { error!(?e); Task::none() } else { - let task = - Task::future(self.db.acquire()) + + Task::future(self.db.acquire()) .and_then(move |db| { Task::perform( presentations::remove_from_db( @@ -1023,17 +1010,13 @@ impl<'a> Library { presentation.id, ), |r| { - match r { - Err(e) => { - error!(?e) - } - _ => (), + if let Err(e) = r { + error!(?e) } Message::None }, ) - }); - task + }) } } else { Task::none() @@ -1041,7 +1024,7 @@ impl<'a> Library { } }) .collect(); - if tasks.len() > 0 { + if !tasks.is_empty() { self.selected_items = None; } Action::Task(Task::batch(tasks)) diff --git a/src/ui/presentation_editor.rs b/src/ui/presentation_editor.rs index d5b32bc..2d8e6e1 100644 --- a/src/ui/presentation_editor.rs +++ b/src/ui/presentation_editor.rs @@ -10,7 +10,7 @@ use cosmic::{ iced_widget::{column, row}, theme, widget::{ - self, button, container, horizontal_space, icon, text, + button, container, horizontal_space, icon, text, text_input, Space, }, Element, Task, @@ -83,8 +83,7 @@ impl PresentationEditor { .presentation .as_ref() .map(|v| v.id) - .unwrap_or_default() - .clone(); + .unwrap_or_default(); let task = Task::perform( pick_presentation(), move |presentation_result| { diff --git a/src/ui/presenter.rs b/src/ui/presenter.rs index 20b4c63..73022dd 100644 --- a/src/ui/presenter.rs +++ b/src/ui/presenter.rs @@ -37,7 +37,7 @@ use crate::{ const REFERENCE_WIDTH: f32 = 1920.0; static DEFAULT_SLIDE: LazyLock = - LazyLock::new(|| Slide::default()); + LazyLock::new(Slide::default); // #[derive(Default, Clone, Debug)] pub(crate) struct Presenter { @@ -155,11 +155,9 @@ impl Presenter { items.iter().fold(0, |a, item| a + item.slides.len()); let slide = - items.get(0).map(|item| item.slides.get(0)).flatten(); - let audio = items - .get(0) - .map(|item| item.slides.get(0).map(|slide| slide.audio())) - .flatten() + items.first().and_then(|item| item.slides.first()); + let audio = items.first() + .and_then(|item| item.slides.first().map(|slide| slide.audio())) .flatten(); Self { @@ -179,7 +177,7 @@ impl Presenter { .expect("Can't open default rodio stream"); ( Arc::new(Sink::connect_new( - &stream_handle.mixer(), + stream_handle.mixer(), )), stream_handle, ) @@ -219,8 +217,7 @@ impl Presenter { if let Some(slide) = self .service .get(item_index) - .map(|item| item.slides.get(slide_index)) - .flatten() + .and_then(|item| item.slides.get(slide_index)) { self.current_item = item_index; self.current_slide_index = slide_index; @@ -473,7 +470,7 @@ impl Presenter { ); let container = slide_view( - &slide, + slide, &self.video, true, false, diff --git a/src/ui/service.rs b/src/ui/service.rs index bebabb5..5b35459 100644 --- a/src/ui/service.rs +++ b/src/ui/service.rs @@ -7,7 +7,7 @@ use cosmic::{ event, mouse, Event, Length, Point, Rectangle, Vector, }, iced_core::{ - self, image::Renderer, layout, renderer, widget::Tree, + self, layout, renderer, widget::Tree, Clipboard, Shell, }, widget::Widget, @@ -196,8 +196,7 @@ impl // We ignore motion if we do not possess drag content by now. if let Some(left_pressed_position) = state.left_pressed_position - { - if position + && position .distance(left_pressed_position) > self.drag_threshold { @@ -217,7 +216,6 @@ impl state.left_pressed_position = None; } - } if !cursor.is_over(layout.bounds()) { state.hovered = false; diff --git a/src/ui/song_editor.rs b/src/ui/song_editor.rs index 0d62812..6a524bd 100644 --- a/src/ui/song_editor.rs +++ b/src/ui/song_editor.rs @@ -308,12 +308,12 @@ impl SongEditor { fn slide_preview(&self) -> Element { if let Some(slides) = &self.song_slides { let slides: Vec> = slides - .into_iter() + .iter() .enumerate() .map(|(index, slide)| { container( slide_view( - &slide, + slide, if index == 0 { &self.video } else { diff --git a/src/ui/video_editor.rs b/src/ui/video_editor.rs index a92a00d..d0d4fd2 100644 --- a/src/ui/video_editor.rs +++ b/src/ui/video_editor.rs @@ -94,8 +94,7 @@ impl VideoEditor { .core_video .as_ref() .map(|v| v.id) - .unwrap_or_default() - .clone(); + .unwrap_or_default(); let task = Task::perform( pick_video(), move |video_result| { diff --git a/src/ui/widgets/draggable/column.rs b/src/ui/widgets/draggable/column.rs index edc2ab9..f6dc41c 100644 --- a/src/ui/widgets/draggable/column.rs +++ b/src/ui/widgets/draggable/column.rs @@ -468,8 +468,7 @@ where Action::Picking { index, origin } => { if let Some(cursor_position) = cursor.position() - { - if cursor_position.distance(origin) + && cursor_position.distance(origin) > self.deadband_zone { // Start dragging @@ -488,7 +487,6 @@ where event_status = event::Status::Captured; } - } } Action::Dragging { origin, index, .. } => { if let Some(cursor_position) = @@ -903,8 +901,7 @@ pub fn default(theme: &Theme) -> Style { Style { scale: 1.05, moved_item_overlay: Color::from(theme.cosmic().primary.base) - .scale_alpha(0.2) - .into(), + .scale_alpha(0.2), ghost_border: Border { width: 1.0, color: theme.cosmic().secondary.base.into(), diff --git a/src/ui/widgets/draggable/row.rs b/src/ui/widgets/draggable/row.rs index c90a5cf..810f589 100644 --- a/src/ui/widgets/draggable/row.rs +++ b/src/ui/widgets/draggable/row.rs @@ -454,8 +454,7 @@ where Action::Picking { index, origin } => { if let Some(cursor_position) = cursor.position() - { - if cursor_position.distance(origin) + && cursor_position.distance(origin) > self.deadband_zone { // Start dragging @@ -474,7 +473,6 @@ where event_status = event::Status::Captured; } - } } Action::Dragging { origin, index, .. } => { if let Some(cursor_position) =