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> {
// 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)),

View file

@ -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())
}
}

View file

@ -283,7 +283,7 @@ pub enum Message {
ImportSuccess(Box<ThemeBuilder>),
InterfaceText(ColorPickerUpdate),
Left,
NewTheme(Theme),
NewTheme(Box<Theme>),
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

View file

@ -631,7 +631,7 @@ impl<'a, Message: 'static + Clone> AppletReorderList<'a, Message> {
info: Vec<Applet<'a>>,
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<Applet<'static>>) -> 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<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> {

View file

@ -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"),
}
)
}
}

View file

@ -405,21 +405,15 @@ fn display_regions<'a>(
.iter()
.filter_map(move |id| model.data::<OutputKey>(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,

View file

@ -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<Self> {
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);