From ef680ae14a52e79619d786138cb9ad9ef4902416 Mon Sep 17 00:00:00 2001 From: pml68 Date: Tue, 31 Dec 2024 18:56:01 +0100 Subject: refactor: apply clippy suggestions --- iced_builder/src/dialogs.rs | 6 +----- iced_builder/src/main.rs | 24 +++++++----------------- iced_builder/src/types/rendered_element.rs | 4 ++-- 3 files changed, 10 insertions(+), 24 deletions(-) (limited to 'iced_builder') diff --git a/iced_builder/src/dialogs.rs b/iced_builder/src/dialogs.rs index 56d22b2..2d916b1 100644 --- a/iced_builder/src/dialogs.rs +++ b/iced_builder/src/dialogs.rs @@ -26,9 +26,5 @@ pub fn unsaved_changes_dialog(description: impl Into) -> bool { .set_description(description) .show(); - if let MessageDialogResult::Ok = result { - true - } else { - false - } + matches!(result, MessageDialogResult::Ok) } diff --git a/iced_builder/src/main.rs b/iced_builder/src/main.rs index 8f3c3fb..437410a 100644 --- a/iced_builder/src/main.rs +++ b/iced_builder/src/main.rs @@ -65,11 +65,7 @@ impl App { }, ); - let config = match config_load { - Ok(config) => config, - Err(_) => Config::default(), - }; - + let config = config_load.unwrap_or_default(); let theme = config.selected_theme(); let mut task = Task::none(); @@ -83,7 +79,7 @@ impl App { } else { warning_dialog(format!( "The file {} does not exist, or isn't a file.", - path.to_string_lossy().to_string() + path.to_string_lossy() )); } } @@ -156,11 +152,10 @@ impl App { None, None, ) - .into() } Message::HandleNew(name, zones) => { let ids: Vec = zones.into_iter().map(|z| z.0).collect(); - if ids.len() > 0 { + if !ids.is_empty() { let action = Action::new( ids, &mut self.project.element_tree.clone(), @@ -172,7 +167,7 @@ impl App { ); match result { Ok(Some(ref element)) => { - self.project.element_tree = Some(element.clone()) + self.project.element_tree = Some(element.clone()); } Err(error) => error_dialog(error.to_string()), _ => {} @@ -189,11 +184,10 @@ impl App { None, None, ) - .into() } Message::HandleMove(element, zones) => { let ids: Vec = zones.into_iter().map(|z| z.0).collect(); - if ids.len() > 0 { + if !ids.is_empty() { let action = Action::new( ids, &mut self.project.element_tree.clone(), @@ -230,13 +224,11 @@ impl App { self.project = Project::new(); self.project_path = None; self.editor_content = text_editor::Content::new(); - } else { - if unsaved_changes_dialog("You have unsaved changes. Do you wish to discard these and create a new project?") { + } else if unsaved_changes_dialog("You have unsaved changes. Do you wish to discard these and create a new project?") { self.is_dirty = false; self.project = Project::new(); self.project_path = None; self.editor_content = text_editor::Content::new(); - } } } } @@ -249,12 +241,10 @@ impl App { Project::from_file(), Message::FileOpened, ); - } else { - if unsaved_changes_dialog("You have unsaved changes. Do you wish to discard these and open another project?") { + } else if unsaved_changes_dialog("You have unsaved changes. Do you wish to discard these and open another project?") { self.is_dirty = false; self.is_loading = true; return Task::perform(Project::from_file(), Message::FileOpened); - } } } } diff --git a/iced_builder/src/types/rendered_element.rs b/iced_builder/src/types/rendered_element.rs index e837abe..d7efed1 100755 --- a/iced_builder/src/types/rendered_element.rs +++ b/iced_builder/src/types/rendered_element.rs @@ -349,12 +349,12 @@ impl<'a> From for Element<'a, Message> { .into() } ElementName::Row => widget::Row::from_iter( - child_elements.into_iter().map(|el| el.into()), + child_elements.into_iter().map(Into::into), ) .padding(20) .into(), ElementName::Column => widget::Column::from_iter( - child_elements.into_iter().map(|el| el.into()), + child_elements.into_iter().map(Into::into), ) .padding(20) .into(), -- cgit v1.2.3