fix: clippy

This commit is contained in:
Ashley Wulber 2024-10-23 10:32:34 -04:00 committed by Ashley Wulber
parent 88fbd8f96b
commit 3cadfec2fb
7 changed files with 38 additions and 71 deletions

View file

@ -218,7 +218,7 @@ impl cosmic::Application for SettingsApp {
fn subscription(&self) -> Subscription<Message> { fn subscription(&self) -> Subscription<Message> {
// Handling of Wayland-specific events received. // Handling of Wayland-specific events received.
let wayland_events = let wayland_events =
event::listen_with(|event, _, id| match event { event::listen_with(|event, _, _id| match event {
iced::Event::PlatformSpecific(PlatformSpecific::Wayland( iced::Event::PlatformSpecific(PlatformSpecific::Wayland(
wayland::Event::Output(wayland::OutputEvent::Created(Some(info)), o), wayland::Event::Output(wayland::OutputEvent::Created(Some(info)), o),
)) if info.name.is_some() => Some(Message::OutputAdded(info, o)), )) if info.name.is_some() => Some(Message::OutputAdded(info, o)),

View file

@ -100,9 +100,9 @@ impl FromStr for PageCommands {
} }
} }
impl ToString for PageCommands { impl std::fmt::Display for PageCommands {
fn to_string(&self) -> String { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
ron::ser::to_string(self).unwrap() write!(f, "{}", ron::ser::to_string(self).unwrap())
} }
} }

View file

@ -283,7 +283,7 @@ pub enum Message {
ImportSuccess(Box<ThemeBuilder>), ImportSuccess(Box<ThemeBuilder>),
InterfaceText(ColorPickerUpdate), InterfaceText(ColorPickerUpdate),
Left, Left,
NewTheme(Theme), NewTheme(Box<Theme>),
PaletteAccent(cosmic::iced::Color), PaletteAccent(cosmic::iced::Color),
Reset, Reset,
Roundness(Roundness), Roundness(Roundness),
@ -477,7 +477,7 @@ impl Page {
} }
Message::NewTheme(theme) => { Message::NewTheme(theme) => {
self.theme = theme; self.theme = *theme;
} }
Message::DarkMode(enabled) => { Message::DarkMode(enabled) => {
if let Some(config) = self.theme_mode_config.as_ref() { 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 { let Some(config) = self.theme_builder_config.as_ref() else {
return Command::none(); return Task::none();
}; };
let spacing = density.into(); let spacing = density.into();
@ -769,7 +769,7 @@ impl Page {
self.icon_theme_active = self self.icon_theme_active = self
.icon_themes .icon_themes
.iter() .iter()
.position(|theme| &theme.id == &active_icon_theme); .position(|theme| theme.id == active_icon_theme);
self.icon_handles = icon_handles; self.icon_handles = icon_handles;
} }
@ -1106,7 +1106,7 @@ impl Page {
window_hint; window_hint;
}); });
Message::NewTheme(new_theme).into() Message::NewTheme(Box::new(new_theme)).into()
} else { } else {
tracing::error!("Failed to get the theme config."); tracing::error!("Failed to get the theme config.");
crate::app::Message::None crate::app::Message::None

View file

@ -631,7 +631,7 @@ impl<'a, Message: 'static + Clone> AppletReorderList<'a, Message> {
info: Vec<Applet<'a>>, info: Vec<Applet<'a>>,
on_create_dnd_source: impl Fn(Applet<'static>) -> Message + 'a, on_create_dnd_source: impl Fn(Applet<'static>) -> Message + 'a,
on_remove: impl Fn(String) -> 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<Applet<'static>>) -> Message + 'a, on_reorder: impl Fn(Vec<Applet<'static>>) -> Message + 'a,
on_apply_reorder: Message, on_apply_reorder: Message,
on_cancel: Message, on_cancel: Message,
@ -1289,13 +1289,6 @@ impl ReorderWidgetState {
pub(crate) fn new() -> ReorderWidgetState { pub(crate) fn new() -> ReorderWidgetState {
ReorderWidgetState::default() ReorderWidgetState::default()
} }
pub(crate) fn dragged_applet(&self) -> Option<Applet<'_>> {
match &self.dragging_state {
DraggingState::Dragging(applet) => Some(applet.borrowed()),
_ => None,
}
}
} }
impl<'a, Message: 'static + Clone> From<AppletReorderList<'a, Message>> for Element<'a, Message> { impl<'a, Message: 'static + Clone> From<AppletReorderList<'a, Message>> for Element<'a, Message> {

View file

@ -343,14 +343,18 @@ pub fn reset_button<
#[derive(Debug, Copy, Clone, PartialEq, Eq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct Anchor(PanelAnchor); pub struct Anchor(PanelAnchor);
impl ToString for Anchor { impl std::fmt::Display for Anchor {
fn to_string(&self) -> String { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.0 { write!(
PanelAnchor::Top => fl!("panel-top"), f,
PanelAnchor::Bottom => fl!("panel-bottom"), "{}",
PanelAnchor::Left => fl!("panel-left"), match self.0 {
PanelAnchor::Right => fl!("panel-right"), 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, Dark,
} }
impl ToString for Appearance { impl std::fmt::Display for Appearance {
fn to_string(&self) -> String { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { write!(
Appearance::Match => fl!("panel-appearance", "match"), f,
Appearance::Light => fl!("panel-appearance", "light"), "{}",
Appearance::Dark => fl!("panel-appearance", "dark"), match self {
} Appearance::Match => fl!("panel-appearance", "match"),
Appearance::Light => fl!("panel-appearance", "light"),
Appearance::Dark => fl!("panel-appearance", "dark"),
}
)
} }
} }

View file

@ -405,21 +405,15 @@ fn display_regions<'a>(
.iter() .iter()
.filter_map(move |id| model.data::<OutputKey>(id)) .filter_map(move |id| model.data::<OutputKey>(id))
.filter_map(move |&key| { .filter_map(move |&key| {
let Some(output) = list.outputs.get(key) else { let output = list.outputs.get(key)?;
return None;
};
if !output.enabled { if !output.enabled {
return None; return None;
} }
let Some(mode_key) = output.current else { let mode_key = output.current?;
return None;
};
let Some(mode) = list.modes.get(mode_key) else { let mode = list.modes.get(mode_key)?;
return None;
};
let (mut width, mut height) = ( let (mut width, mut height) = (
(mode.size.0 as f32 / output.scale as f32) / UNIT_PIXELS, (mode.size.0 as f32 / output.scale as f32) / UNIT_PIXELS,

View file

@ -1,6 +1,6 @@
use chrono::{Duration, TimeDelta}; use chrono::{Duration, TimeDelta};
use futures::FutureExt; use futures::FutureExt;
use futures::{future::join_all, TryFutureExt}; use futures::future::join_all;
use upower_dbus::{BatteryState, BatteryType, DeviceProxy}; use upower_dbus::{BatteryState, BatteryType, DeviceProxy};
use zbus::Connection; 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 { impl ConnectedDevice {
async fn from_device_maybe(proxy: DeviceProxy<'_>) -> Option<Self> { async fn from_device_maybe(proxy: DeviceProxy<'_>) -> Option<Self> {
let device_type = proxy.type_().await.unwrap_or(BatteryType::Unknown); let device_type = proxy.type_().await.unwrap_or(BatteryType::Unknown);
@ -515,7 +487,7 @@ mod tests {
let (actual, expected) = case; let (actual, expected) = case;
let battery = Battery { let battery = Battery {
remaining_duration: Duration::new(actual, 0).unwrap(), remaining_duration: Duration::new(actual, 0).unwrap(),
on_battery: true, is_charging: false,
..Default::default() ..Default::default()
}; };
assert_eq!(battery.remaining_time(), expected); assert_eq!(battery.remaining_time(), expected);