Skip to content

Commit 050c882

Browse files
committed
chore: refactor code following clippy guideline
1 parent df43c94 commit 050c882

File tree

22 files changed

+204
-210
lines changed

22 files changed

+204
-210
lines changed

cosmic-settings/src/app.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ impl SettingsApp {
5959
match cmd {
6060
PageCommands::About => self.pages.page_id::<system::about::Page>(),
6161
PageCommands::Appearance => self.pages.page_id::<desktop::appearance::Page>(),
62-
PageCommands::Bluetooth => None,
6362
PageCommands::DateTime => self.pages.page_id::<time::date::Page>(),
6463
PageCommands::Desktop => self.pages.page_id::<desktop::Page>(),
6564
PageCommands::Displays => self.pages.page_id::<display::Page>(),
@@ -68,7 +67,6 @@ impl SettingsApp {
6867
PageCommands::Input => self.pages.page_id::<input::Page>(),
6968
PageCommands::Keyboard => self.pages.page_id::<input::keyboard::Page>(),
7069
PageCommands::Mouse => self.pages.page_id::<input::mouse::Page>(),
71-
PageCommands::Network => None,
7270
PageCommands::Panel => self.pages.page_id::<desktop::panel::Page>(),
7371
PageCommands::Power => self.pages.page_id::<power::Page>(),
7472
PageCommands::RegionLanguage => self.pages.page_id::<time::region::Page>(),
@@ -82,6 +80,8 @@ impl SettingsApp {
8280
self.pages.page_id::<desktop::window_management::Page>()
8381
}
8482
PageCommands::Workspaces => self.pages.page_id::<desktop::workspaces::Page>(),
83+
// Unimplemented
84+
PageCommands::Bluetooth | PageCommands::Network => None,
8585
}
8686
}
8787

cosmic-settings/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ impl FromStr for PageCommands {
9494
}
9595
}
9696

97-
impl ToString for PageCommands {
98-
fn to_string(&self) -> String {
99-
ron::ser::to_string(self).unwrap()
97+
impl std::fmt::Display for PageCommands {
98+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
99+
f.write_str(&ron::ser::to_string(self).map_err(|_| std::fmt::Error)?)
100100
}
101101
}
102102

cosmic-settings/src/pages/desktop/appearance.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ impl Page {
444444
.zip(self.icon_handles.iter())
445445
.enumerate()
446446
.map(|(i, (theme, handles))| {
447-
let selected = active.map(|j| i == j).unwrap_or_default();
447+
let selected = active.is_some_and(|j| i == j);
448448
icon_theme_button(&theme.name, handles, i, selected)
449449
})
450450
.collect(),
@@ -496,7 +496,7 @@ impl Page {
496496
Message::IconTheme(id) => {
497497
if let Some(theme) = self.icon_themes.get(id).cloned() {
498498
self.icon_theme_active = Some(id);
499-
self.tk.icon_theme = theme.id.clone();
499+
self.tk.icon_theme = theme.id;
500500

501501
if let Some(ref config) = self.tk_config {
502502
let _ = self.tk.write_entry(config);
@@ -598,7 +598,7 @@ impl Page {
598598
self.icon_theme_active = self
599599
.icon_themes
600600
.iter()
601-
.position(|theme| &theme.id == &self.tk.icon_theme);
601+
.position(|theme| theme.id == self.tk.icon_theme);
602602
self.icon_handles = icon_handles;
603603
Command::none()
604604
}
@@ -1689,7 +1689,7 @@ async fn set_gnome_icon_theme(theme: String) {
16891689
.await;
16901690
}
16911691

1692-
/// Generate [icon::Handle]s to use for icon theme previews.
1692+
/// Generate [`icon::Handle`]s to use for icon theme previews.
16931693
fn preview_handles(theme: String, inherits: Vec<String>) -> [icon::Handle; ICON_PREV_N] {
16941694
// Cache current default and set icon theme as a temporary default
16951695
let default = cosmic::icon_theme::default();

cosmic-settings/src/pages/desktop/dock/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ use crate::pages::desktop::panel::inner::{
1616
add_panel, behavior_and_position, configuration, reset_button, style,
1717
};
1818

19-
use super::panel::inner::{self, PageInner, PanelPage};
19+
use super::panel::inner;
2020

2121
pub mod applets;
2222

2323
pub struct Page {
24-
inner: PageInner,
24+
inner: inner::Page,
2525
}
2626

2727
#[derive(Clone, Debug)]
@@ -75,12 +75,12 @@ impl page::AutoBind<crate::pages::Message> for Page {
7575
}
7676
}
7777

78-
impl PanelPage for Page {
79-
fn inner(&self) -> &PageInner {
78+
impl inner::PanelPage for Page {
79+
fn inner(&self) -> &inner::Page {
8080
&self.inner
8181
}
8282

83-
fn inner_mut(&mut self) -> &mut PageInner {
83+
fn inner_mut(&mut self) -> &mut inner::Page {
8484
&mut self.inner
8585
}
8686

@@ -130,7 +130,7 @@ impl Default for Page {
130130
.ok();
131131
let container_config = CosmicPanelContainerConfig::load().ok();
132132
Self {
133-
inner: PageInner {
133+
inner: inner::Page {
134134
config_helper,
135135
panel_config,
136136
container_config,

cosmic-settings/src/pages/desktop/panel/applets_inner.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,9 @@ impl Page {
324324
.into()
325325
}
326326

327+
/// # Panics
328+
///
329+
/// Panics if the wings of the added applet are None.
327330
#[allow(clippy::too_many_lines)]
328331
pub fn update(&mut self, message: Message) -> Command<app::Message> {
329332
match message {
@@ -666,7 +669,7 @@ impl<'a, Message: 'static + Clone> AppletReorderList<'a, Message> {
666669
) -> Message
667670
+ 'a,
668671
on_remove: impl Fn(String) -> Message + 'a,
669-
on_details: impl Fn(String) -> Message + 'a,
672+
_on_details: impl Fn(String) -> Message + 'a,
670673
on_reorder: impl Fn(Vec<Applet<'static>>) -> Message + 'a,
671674
on_apply_reorder: Message,
672675
on_cancel: Message,
@@ -972,7 +975,10 @@ where
972975
}
973976
DraggingState::Dragging(applet) => match &event {
974977
event::Event::PlatformSpecific(PlatformSpecific::Wayland(
975-
wayland::Event::DataSource(wayland::DataSourceEvent::DndFinished),
978+
wayland::Event::DataSource(
979+
wayland::DataSourceEvent::DndFinished
980+
| wayland::DataSourceEvent::DndDropPerformed,
981+
),
976982
)) => {
977983
ret = event::Status::Captured;
978984
DraggingState::None
@@ -986,13 +992,6 @@ where
986992
}
987993
DraggingState::None
988994
}
989-
event::Event::PlatformSpecific(PlatformSpecific::Wayland(
990-
wayland::Event::DataSource(wayland::DataSourceEvent::DndDropPerformed),
991-
)) => {
992-
ret = event::Status::Captured;
993-
994-
DraggingState::None
995-
}
996995
_ => DraggingState::Dragging(applet),
997996
},
998997
DraggingState::Pressed(start) => {

cosmic-settings/src/pages/desktop/panel/inner.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use cosmic_settings_page::{self as page, Section};
1818
use slab::Slab;
1919
use std::collections::HashMap;
2020

21-
pub struct PageInner {
21+
pub struct Page {
2222
pub(crate) config_helper: Option<cosmic_config::Config>,
2323
pub(crate) panel_config: Option<CosmicPanelConfig>,
2424
pub outputs: Vec<String>,
@@ -31,7 +31,7 @@ pub struct PageInner {
3131
pub(crate) system_container: Option<CosmicPanelContainerConfig>,
3232
}
3333

34-
impl Default for PageInner {
34+
impl Default for Page {
3535
fn default() -> Self {
3636
Self {
3737
config_helper: Option::default(),
@@ -72,9 +72,9 @@ impl Default for PageInner {
7272
}
7373

7474
pub trait PanelPage {
75-
fn inner(&self) -> &PageInner;
75+
fn inner(&self) -> &Page;
7676

77-
fn inner_mut(&mut self) -> &mut PageInner;
77+
fn inner_mut(&mut self) -> &mut Page;
7878

7979
fn autohide_label(&self) -> String;
8080

@@ -336,14 +336,14 @@ pub fn reset_button<
336336
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
337337
pub struct Anchor(PanelAnchor);
338338

339-
impl ToString for Anchor {
340-
fn to_string(&self) -> String {
341-
match self.0 {
339+
impl std::fmt::Display for Anchor {
340+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
341+
f.write_str(&match self.0 {
342342
PanelAnchor::Top => fl!("panel-top"),
343343
PanelAnchor::Bottom => fl!("panel-bottom"),
344344
PanelAnchor::Left => fl!("panel-left"),
345345
PanelAnchor::Right => fl!("panel-right"),
346-
}
346+
})
347347
}
348348
}
349349

@@ -354,13 +354,13 @@ pub enum Appearance {
354354
Dark,
355355
}
356356

357-
impl ToString for Appearance {
358-
fn to_string(&self) -> String {
359-
match self {
357+
impl std::fmt::Display for Appearance {
358+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
359+
f.write_str(&match self {
360360
Appearance::Match => fl!("panel-appearance", "match"),
361361
Appearance::Light => fl!("panel-appearance", "light"),
362362
Appearance::Dark => fl!("panel-appearance", "dark"),
363-
}
363+
})
364364
}
365365
}
366366

@@ -404,7 +404,7 @@ pub enum Message {
404404
FullReset,
405405
}
406406

407-
impl PageInner {
407+
impl Page {
408408
#[allow(clippy::too_many_lines)]
409409
pub fn update(&mut self, message: Message) {
410410
let Some(helper) = self.config_helper.as_ref() else {

cosmic-settings/src/pages/desktop/panel/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@ use crate::pages::desktop::panel::inner::{
99
add_panel, behavior_and_position, configuration, reset_button, style,
1010
};
1111

12-
use self::inner::{PageInner, PanelPage};
13-
1412
pub mod applets_inner;
1513
pub mod inner;
1614

1715
pub struct Page {
18-
inner: PageInner,
16+
inner: inner::Page,
1917
}
2018

2119
#[derive(Clone, Debug)]
@@ -33,12 +31,12 @@ impl page::AutoBind<crate::pages::Message> for Page {
3331
}
3432
}
3533

36-
impl PanelPage for Page {
37-
fn inner(&self) -> &PageInner {
34+
impl inner::PanelPage for Page {
35+
fn inner(&self) -> &inner::Page {
3836
&self.inner
3937
}
4038

41-
fn inner_mut(&mut self) -> &mut PageInner {
39+
fn inner_mut(&mut self) -> &mut inner::Page {
4240
&mut self.inner
4341
}
4442

@@ -87,7 +85,7 @@ impl Default for Page {
8785
.ok();
8886
let container_config = CosmicPanelContainerConfig::load().ok();
8987
Self {
90-
inner: PageInner {
88+
inner: inner::Page {
9189
config_helper,
9290
panel_config,
9391
container_config,

0 commit comments

Comments
 (0)