From 3cadfec2fb87a05eca9d9cd6920b46f6f548e7b9 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Wed, 23 Oct 2024 10:32:34 -0400 Subject: [PATCH] fix: clippy --- cosmic-settings/src/app.rs | 2 +- cosmic-settings/src/main.rs | 6 +-- .../src/pages/desktop/appearance/mod.rs | 10 ++--- .../src/pages/desktop/panel/applets_inner.rs | 9 +---- .../src/pages/desktop/panel/inner.rs | 38 +++++++++++-------- .../src/pages/display/arrangement.rs | 12 ++---- .../src/pages/power/backend/mod.rs | 32 +--------------- 7 files changed, 38 insertions(+), 71 deletions(-) diff --git a/cosmic-settings/src/app.rs b/cosmic-settings/src/app.rs index 43355da..a04aeec 100644 --- a/cosmic-settings/src/app.rs +++ b/cosmic-settings/src/app.rs @@ -218,7 +218,7 @@ impl cosmic::Application for SettingsApp { fn subscription(&self) -> Subscription { // Handling of Wayland-specific events received. let wayland_events = - event::listen_with(|event, _, id| match event { + event::listen_with(|event, _, _id| match event { iced::Event::PlatformSpecific(PlatformSpecific::Wayland( wayland::Event::Output(wayland::OutputEvent::Created(Some(info)), o), )) if info.name.is_some() => Some(Message::OutputAdded(info, o)), diff --git a/cosmic-settings/src/main.rs b/cosmic-settings/src/main.rs index 6bba1e8..19a5e66 100644 --- a/cosmic-settings/src/main.rs +++ b/cosmic-settings/src/main.rs @@ -100,9 +100,9 @@ impl FromStr for PageCommands { } } -impl ToString for PageCommands { - fn to_string(&self) -> String { - ron::ser::to_string(self).unwrap() +impl std::fmt::Display for PageCommands { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", ron::ser::to_string(self).unwrap()) } } diff --git a/cosmic-settings/src/pages/desktop/appearance/mod.rs b/cosmic-settings/src/pages/desktop/appearance/mod.rs index 69d9f56..aae4085 100644 --- a/cosmic-settings/src/pages/desktop/appearance/mod.rs +++ b/cosmic-settings/src/pages/desktop/appearance/mod.rs @@ -283,7 +283,7 @@ pub enum Message { ImportSuccess(Box), InterfaceText(ColorPickerUpdate), Left, - NewTheme(Theme), + NewTheme(Box), PaletteAccent(cosmic::iced::Color), Reset, Roundness(Roundness), @@ -477,7 +477,7 @@ impl Page { } Message::NewTheme(theme) => { - self.theme = theme; + self.theme = *theme; } Message::DarkMode(enabled) => { if let Some(config) = self.theme_mode_config.as_ref() { @@ -743,7 +743,7 @@ impl Page { } let Some(config) = self.theme_builder_config.as_ref() else { - return Command::none(); + return Task::none(); }; let spacing = density.into(); @@ -769,7 +769,7 @@ impl Page { self.icon_theme_active = self .icon_themes .iter() - .position(|theme| &theme.id == &active_icon_theme); + .position(|theme| theme.id == active_icon_theme); self.icon_handles = icon_handles; } @@ -1106,7 +1106,7 @@ impl Page { window_hint; }); - Message::NewTheme(new_theme).into() + Message::NewTheme(Box::new(new_theme)).into() } else { tracing::error!("Failed to get the theme config."); crate::app::Message::None diff --git a/cosmic-settings/src/pages/desktop/panel/applets_inner.rs b/cosmic-settings/src/pages/desktop/panel/applets_inner.rs index e4fd40d..6a308f4 100644 --- a/cosmic-settings/src/pages/desktop/panel/applets_inner.rs +++ b/cosmic-settings/src/pages/desktop/panel/applets_inner.rs @@ -631,7 +631,7 @@ impl<'a, Message: 'static + Clone> AppletReorderList<'a, Message> { info: Vec>, on_create_dnd_source: impl Fn(Applet<'static>) -> Message + 'a, on_remove: impl Fn(String) -> Message + 'a, - on_details: impl Fn(String) -> Message + 'a, + _on_details: impl Fn(String) -> Message + 'a, on_reorder: impl Fn(Vec>) -> Message + 'a, on_apply_reorder: Message, on_cancel: Message, @@ -1289,13 +1289,6 @@ impl ReorderWidgetState { pub(crate) fn new() -> ReorderWidgetState { ReorderWidgetState::default() } - - pub(crate) fn dragged_applet(&self) -> Option> { - match &self.dragging_state { - DraggingState::Dragging(applet) => Some(applet.borrowed()), - _ => None, - } - } } impl<'a, Message: 'static + Clone> From> for Element<'a, Message> { diff --git a/cosmic-settings/src/pages/desktop/panel/inner.rs b/cosmic-settings/src/pages/desktop/panel/inner.rs index 1a4091d..121572c 100644 --- a/cosmic-settings/src/pages/desktop/panel/inner.rs +++ b/cosmic-settings/src/pages/desktop/panel/inner.rs @@ -343,14 +343,18 @@ pub fn reset_button< #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub struct Anchor(PanelAnchor); -impl ToString for Anchor { - fn to_string(&self) -> String { - match self.0 { - PanelAnchor::Top => fl!("panel-top"), - PanelAnchor::Bottom => fl!("panel-bottom"), - PanelAnchor::Left => fl!("panel-left"), - PanelAnchor::Right => fl!("panel-right"), - } +impl std::fmt::Display for Anchor { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + match self.0 { + PanelAnchor::Top => fl!("panel-top"), + PanelAnchor::Bottom => fl!("panel-bottom"), + PanelAnchor::Left => fl!("panel-left"), + PanelAnchor::Right => fl!("panel-right"), + } + ) } } @@ -361,13 +365,17 @@ pub enum Appearance { Dark, } -impl ToString for Appearance { - fn to_string(&self) -> String { - match self { - Appearance::Match => fl!("panel-appearance", "match"), - Appearance::Light => fl!("panel-appearance", "light"), - Appearance::Dark => fl!("panel-appearance", "dark"), - } +impl std::fmt::Display for Appearance { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + match self { + Appearance::Match => fl!("panel-appearance", "match"), + Appearance::Light => fl!("panel-appearance", "light"), + Appearance::Dark => fl!("panel-appearance", "dark"), + } + ) } } diff --git a/cosmic-settings/src/pages/display/arrangement.rs b/cosmic-settings/src/pages/display/arrangement.rs index aa1792b..b9b1ea1 100644 --- a/cosmic-settings/src/pages/display/arrangement.rs +++ b/cosmic-settings/src/pages/display/arrangement.rs @@ -405,21 +405,15 @@ fn display_regions<'a>( .iter() .filter_map(move |id| model.data::(id)) .filter_map(move |&key| { - let Some(output) = list.outputs.get(key) else { - return None; - }; + let output = list.outputs.get(key)?; if !output.enabled { return None; } - let Some(mode_key) = output.current else { - return None; - }; + let mode_key = output.current?; - let Some(mode) = list.modes.get(mode_key) else { - return None; - }; + let mode = list.modes.get(mode_key)?; let (mut width, mut height) = ( (mode.size.0 as f32 / output.scale as f32) / UNIT_PIXELS, diff --git a/cosmic-settings/src/pages/power/backend/mod.rs b/cosmic-settings/src/pages/power/backend/mod.rs index 9223357..6badc34 100644 --- a/cosmic-settings/src/pages/power/backend/mod.rs +++ b/cosmic-settings/src/pages/power/backend/mod.rs @@ -1,6 +1,6 @@ use chrono::{Duration, TimeDelta}; use futures::FutureExt; -use futures::{future::join_all, TryFutureExt}; +use futures::future::join_all; use upower_dbus::{BatteryState, BatteryType, DeviceProxy}; use zbus::Connection; @@ -403,34 +403,6 @@ impl Battery { } } -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_can_format_battery_remaining() { - let cases = [ - (59, "Less than a minute until empty"), - (300, "5 minutes until empty"), - (305, "5 minutes until empty"), - (330, "5 minutes until empty"), - (360, "6 minutes until empty"), - (3660, "1 hour and 1 minute until empty"), - (10800, "3 hours until empty"), - (969400, "11 days, 5 hours and 16 minutes until empty"), - ]; - for case in cases { - let (actual, expected) = case; - let battery = Battery { - remaining_duration: Duration::new(actual, 0).unwrap(), - is_charging: false, - ..Default::default() - }; - assert_eq!(battery.remaining_time(), expected); - } - } -} - impl ConnectedDevice { async fn from_device_maybe(proxy: DeviceProxy<'_>) -> Option { let device_type = proxy.type_().await.unwrap_or(BatteryType::Unknown); @@ -515,7 +487,7 @@ mod tests { let (actual, expected) = case; let battery = Battery { remaining_duration: Duration::new(actual, 0).unwrap(), - on_battery: true, + is_charging: false, ..Default::default() }; assert_eq!(battery.remaining_time(), expected);