From b9723dd5e028dc99f0ba59dea4d53c2ae520d8f9 Mon Sep 17 00:00:00 2001 From: "daniel.eades" Date: Thu, 16 Nov 2023 18:32:31 +0000 Subject: [PATCH] use 'Self' to refer to own type --- cosmic-app-list/src/app.rs | 4 +-- cosmic-app-list/src/config.rs | 4 +-- cosmic-applet-audio/src/main.rs | 20 ++++++------- cosmic-applet-audio/src/pulse.rs | 28 ++++++++----------- cosmic-applet-battery/src/app.rs | 2 +- cosmic-applet-bluetooth/src/app.rs | 2 +- cosmic-applet-graphics/src/window.rs | 8 +++--- cosmic-applet-network/src/app.rs | 14 +++++----- .../src/network_manager/current_networks.rs | 6 ++-- cosmic-applet-notifications/src/main.rs | 2 +- cosmic-applet-power/src/main.rs | 4 +-- cosmic-applet-tiling/src/window.rs | 2 +- cosmic-applet-time/src/window.rs | 2 +- .../src/components/app.rs | 2 +- cosmic-panel-button/src/main.rs | 2 +- 15 files changed, 48 insertions(+), 54 deletions(-) diff --git a/cosmic-app-list/src/app.rs b/cosmic-app-list/src/app.rs index c5169963..6017f87e 100755 --- a/cosmic-app-list/src/app.rs +++ b/cosmic-app-list/src/app.rs @@ -108,7 +108,7 @@ impl DockItem { rectangle_tracker: Option<&RectangleTracker>, interaction_enabled: bool, ) -> Element<'_, Message> { - let DockItem { + let Self { toplevels, desktop_info, id, @@ -377,7 +377,7 @@ impl cosmic::Application for CosmicAppList { _flags: Self::Flags, ) -> (Self, iced::Command>) { let config = config::AppListConfig::load().unwrap_or_default(); - let mut self_ = CosmicAppList { + let mut self_ = Self { core, favorite_list: desktop_info_for_app_ids(config.favorites.clone()) .into_iter() diff --git a/cosmic-app-list/src/config.rs b/cosmic-app-list/src/config.rs index 211d2851..235d3fdd 100644 --- a/cosmic-app-list/src/config.rs +++ b/cosmic-app-list/src/config.rs @@ -26,7 +26,7 @@ pub struct AppListConfig { impl AppListConfig { // TODO async? /// load config with the provided name - pub fn load() -> anyhow::Result { + pub fn load() -> anyhow::Result { let mut relative_path = PathBuf::from(APP_ID); relative_path.push("config.ron"); let file = match BaseDirectories::new() @@ -40,7 +40,7 @@ impl AppListConfig { } }; - ron::de::from_reader::<_, AppListConfig>(file) + ron::de::from_reader::<_, Self>(file) .map_err(|err| anyhow!("Failed to parse config file: {}", err)) } diff --git a/cosmic-applet-audio/src/main.rs b/cosmic-applet-audio/src/main.rs index 72b78c0f..e50918fd 100644 --- a/cosmic-applet-audio/src/main.rs +++ b/cosmic-applet-audio/src/main.rs @@ -261,9 +261,9 @@ impl cosmic::Application for Audio { type Flags = (); const APP_ID: &'static str = "com.system76.CosmicAppletAudio"; - fn init(core: cosmic::app::Core, _flags: ()) -> (Audio, Command) { + fn init(core: cosmic::app::Core, _flags: ()) -> (Self, Command) { ( - Audio { + Self { core, is_open: IsOpen::None, current_output: None, @@ -797,27 +797,27 @@ enum PulseState { impl PulseState { fn connection(&mut self) -> Option<&mut pulse::Connection> { match self { - PulseState::Disconnected(c) => Some(c), - PulseState::Connected(c) => Some(c), - PulseState::Init => None, + Self::Disconnected(c) => Some(c), + Self::Connected(c) => Some(c), + Self::Init => None, } } fn connected(&mut self) { - if let PulseState::Disconnected(c) = self { - *self = PulseState::Connected(c.clone()); + if let Self::Disconnected(c) = self { + *self = Self::Connected(c.clone()); } } fn disconnected(&mut self) { - if let PulseState::Connected(c) = self { - *self = PulseState::Disconnected(c.clone()); + if let Self::Connected(c) = self { + *self = Self::Disconnected(c.clone()); } } } impl Default for IsOpen { fn default() -> Self { - IsOpen::None + Self::None } } diff --git a/cosmic-applet-audio/src/pulse.rs b/cosmic-applet-audio/src/pulse.rs index ce3d2ac7..636b26c7 100644 --- a/cosmic-applet-audio/src/pulse.rs +++ b/cosmic-applet-audio/src/pulse.rs @@ -157,7 +157,7 @@ struct PulseHandle { impl PulseHandle { // Create pulse server thread, and bidirectional comms - pub fn new() -> PulseHandle { + pub fn new() -> Self { let (to_pulse, mut to_pulse_recv) = tokio::sync::mpsc::channel(10); let (mut from_pulse_send, from_pulse) = tokio::sync::mpsc::channel(10); // get initial connection status @@ -195,9 +195,7 @@ impl PulseHandle { .send(Message::SetDefaultSink(sink)) .await .unwrap(), - Err(_) => { - PulseHandle::send_disconnected(&mut from_pulse_send).await - } + Err(_) => Self::send_disconnected(&mut from_pulse_send).await, } } Message::GetDefaultSource => { @@ -212,7 +210,7 @@ impl PulseHandle { .unwrap(), Err(e) => { tracing::error!("ERROR! {:?}", e); - PulseHandle::send_disconnected(&mut from_pulse_send).await; + Self::send_disconnected(&mut from_pulse_send).await; } } } @@ -226,9 +224,7 @@ impl PulseHandle { .send(Message::SetSinks(sinks)) .await .unwrap(), - Err(_) => { - PulseHandle::send_disconnected(&mut from_pulse_send).await - } + Err(_) => Self::send_disconnected(&mut from_pulse_send).await, } } Message::GetSources => { @@ -241,9 +237,7 @@ impl PulseHandle { .send(Message::SetSources(sinks)) .await .unwrap(), - Err(_) => { - PulseHandle::send_disconnected(&mut from_pulse_send).await - } + Err(_) => Self::send_disconnected(&mut from_pulse_send).await, } } Message::SetSinkVolumeByName(name, channel_volumes) => { @@ -269,7 +263,7 @@ impl PulseHandle { tracing::trace!("getting server info..."); if cur_server.get_server_info().is_err() { tracing::warn!("got error, server must be disconnected..."); - PulseHandle::send_disconnected(&mut from_pulse_send).await; + Self::send_disconnected(&mut from_pulse_send).await; } else { tracing::trace!("got server info, still connected..."); server = Some(cur_server); @@ -278,7 +272,7 @@ impl PulseHandle { match PulseServer::connect().and_then(|server| server.init()) { Ok(new_server) => { tracing::info!("Connected to server"); - PulseHandle::send_connected(&mut from_pulse_send).await; + Self::send_connected(&mut from_pulse_send).await; server = Some(new_server); } Err(err) => { @@ -336,7 +330,7 @@ impl PulseHandle { } }); }); - PulseHandle { + Self { to_pulse, from_pulse, } @@ -372,7 +366,7 @@ enum PulseServerError<'a> { // https://crates.io/crates/pulsectl-rs impl PulseServer { // connect() requires init() to be run after - pub fn connect() -> Result> { + pub fn connect() -> Result> { // TODO: fix app name, should be variable let mut proplist = Proplist::new().unwrap(); proplist @@ -398,7 +392,7 @@ impl PulseServer { .connect(None, pulse::context::FlagSet::NOFLAGS, None) .map_err(PulseServerError::PAErr)?; - Ok(PulseServer { + Ok(Self { mainloop, context, introspector, @@ -729,7 +723,7 @@ pub struct ServerInfo { impl<'a> From<&'a pulse::context::introspect::ServerInfo<'a>> for ServerInfo { fn from(info: &'a pulse::context::introspect::ServerInfo<'a>) -> Self { - ServerInfo { + Self { user_name: info.user_name.as_ref().map(|cow| cow.to_string()), host_name: info.host_name.as_ref().map(|cow| cow.to_string()), server_version: info.server_version.as_ref().map(|cow| cow.to_string()), diff --git a/cosmic-applet-battery/src/app.rs b/cosmic-applet-battery/src/app.rs index 3f1a03d2..48a4d6bf 100644 --- a/cosmic-applet-battery/src/app.rs +++ b/cosmic-applet-battery/src/app.rs @@ -162,7 +162,7 @@ impl cosmic::Application for CosmicBatteryApplet { cosmic::iced::Command>, ) { ( - CosmicBatteryApplet { + Self { core, icon_name: "battery-symbolic".to_string(), display_icon_name: "display-brightness-symbolic".to_string(), diff --git a/cosmic-applet-bluetooth/src/app.rs b/cosmic-applet-bluetooth/src/app.rs index efbc9b94..1ccd8437 100644 --- a/cosmic-applet-bluetooth/src/app.rs +++ b/cosmic-applet-bluetooth/src/app.rs @@ -75,7 +75,7 @@ impl cosmic::Application for CosmicBluetoothApplet { _flags: Self::Flags, ) -> (Self, iced::Command>) { ( - CosmicBluetoothApplet { + Self { core, icon_name: "bluetooth-symbolic".to_string(), ..Default::default() diff --git a/cosmic-applet-graphics/src/window.rs b/cosmic-applet-graphics/src/window.rs index 60967ccd..a3c874f9 100644 --- a/cosmic-applet-graphics/src/window.rs +++ b/cosmic-applet-graphics/src/window.rs @@ -30,9 +30,9 @@ enum GraphicsMode { impl GraphicsMode { fn inner(&self) -> Graphics { match self { - GraphicsMode::Selected { new, .. } => *new, - GraphicsMode::Current(g) => *g, - GraphicsMode::Applied(g) => *g, + Self::Selected { new, .. } => *new, + Self::Current(g) => *g, + Self::Applied(g) => *g, } } } @@ -67,7 +67,7 @@ impl cosmic::Application for Window { core: cosmic::app::Core, _flags: Self::Flags, ) -> (Self, iced::Command>) { - let window = Window { + let window = Self { core, ..Default::default() }; diff --git a/cosmic-applet-network/src/app.rs b/cosmic-applet-network/src/app.rs index c06def0d..4482debc 100644 --- a/cosmic-applet-network/src/app.rs +++ b/cosmic-applet-network/src/app.rs @@ -52,12 +52,12 @@ enum NewConnectionState { impl NewConnectionState { pub fn ssid(&self) -> &str { &match self { - NewConnectionState::EnterPassword { + Self::EnterPassword { access_point, password: _, } => access_point, - NewConnectionState::Waiting(ap) => ap, - NewConnectionState::Failure(ap) => ap, + Self::Waiting(ap) => ap, + Self::Failure(ap) => ap, } .ssid } @@ -66,12 +66,12 @@ impl NewConnectionState { impl Into for NewConnectionState { fn into(self) -> AccessPoint { match self { - NewConnectionState::EnterPassword { + Self::EnterPassword { access_point, password: _, } => access_point, - NewConnectionState::Waiting(access_point) => access_point, - NewConnectionState::Failure(access_point) => access_point, + Self::Waiting(access_point) => access_point, + Self::Failure(access_point) => access_point, } } } @@ -192,7 +192,7 @@ impl cosmic::Application for CosmicNetworkApplet { fn init(core: cosmic::app::Core, _flags: ()) -> (Self, Command) { ( - CosmicNetworkApplet { + Self { core, icon_name: "network-offline-symbolic".to_string(), ..Default::default() diff --git a/cosmic-applet-network/src/network_manager/current_networks.rs b/cosmic-applet-network/src/network_manager/current_networks.rs index c615ce35..271759c3 100644 --- a/cosmic-applet-network/src/network_manager/current_networks.rs +++ b/cosmic-applet-network/src/network_manager/current_networks.rs @@ -103,9 +103,9 @@ pub enum ActiveConnectionInfo { impl ActiveConnectionInfo { pub fn name(&self) -> String { match &self { - ActiveConnectionInfo::Wired { name, .. } => name.clone(), - ActiveConnectionInfo::WiFi { name, .. } => name.clone(), - ActiveConnectionInfo::Vpn { name, .. } => name.clone(), + Self::Wired { name, .. } => name.clone(), + Self::WiFi { name, .. } => name.clone(), + Self::Vpn { name, .. } => name.clone(), } } } diff --git a/cosmic-applet-notifications/src/main.rs b/cosmic-applet-notifications/src/main.rs index 6ac9781e..2168ef27 100644 --- a/cosmic-applet-notifications/src/main.rs +++ b/cosmic-applet-notifications/src/main.rs @@ -124,7 +124,7 @@ impl cosmic::Application for Notifications { }) }) .unwrap_or_default(); - let mut _self = Notifications { + let mut _self = Self { core, config_helper: helper, config, diff --git a/cosmic-applet-power/src/main.rs b/cosmic-applet-power/src/main.rs index 183fed7a..b4ac3dc7 100644 --- a/cosmic-applet-power/src/main.rs +++ b/cosmic-applet-power/src/main.rs @@ -93,9 +93,9 @@ impl cosmic::Application for Power { &mut self.core } - fn init(core: cosmic::app::Core, _flags: ()) -> (Power, Command) { + fn init(core: cosmic::app::Core, _flags: ()) -> (Self, Command) { ( - Power { + Self { core, icon_name: "system-shutdown-symbolic".to_string(), ..Default::default() diff --git a/cosmic-applet-tiling/src/window.rs b/cosmic-applet-tiling/src/window.rs index 48e6f8d3..e5acc2d3 100644 --- a/cosmic-applet-tiling/src/window.rs +++ b/cosmic-applet-tiling/src/window.rs @@ -68,7 +68,7 @@ impl cosmic::Application for Window { gaps.value = core.system_theme().cosmic().gaps.1 as i32; let mut active_hint = spin_button::Model::default().max(99).min(0).step(1); active_hint.value = core.system_theme().cosmic().active_hint as i32; - let window = Window { + let window = Self { core, gaps, active_hint, diff --git a/cosmic-applet-time/src/window.rs b/cosmic-applet-time/src/window.rs index 2a19f982..edff6b1a 100644 --- a/cosmic-applet-time/src/window.rs +++ b/cosmic-applet-time/src/window.rs @@ -60,7 +60,7 @@ impl cosmic::Application for Window { _flags: Self::Flags, ) -> (Self, cosmic::iced::Command>) { ( - Window { + Self { core, popup: None, id_ctr: 0, diff --git a/cosmic-applet-workspaces/src/components/app.rs b/cosmic-applet-workspaces/src/components/app.rs index e6314d2f..b8dedf83 100644 --- a/cosmic-applet-workspaces/src/components/app.rs +++ b/cosmic-applet-workspaces/src/components/app.rs @@ -54,7 +54,7 @@ impl cosmic::Application for IcedWorkspacesApplet { cosmic::iced::Command>, ) { ( - IcedWorkspacesApplet { + Self { layout: match &core.applet.anchor { PanelAnchor::Left | PanelAnchor::Right => Layout::Column, PanelAnchor::Top | PanelAnchor::Bottom => Layout::Row, diff --git a/cosmic-panel-button/src/main.rs b/cosmic-panel-button/src/main.rs index 82595d89..9a24310a 100644 --- a/cosmic-panel-button/src/main.rs +++ b/cosmic-panel-button/src/main.rs @@ -27,7 +27,7 @@ impl cosmic::Application for Button { const APP_ID: &'static str = "com.system76.CosmicPanelButton"; fn init(core: cosmic::app::Core, desktop: Desktop) -> (Self, app::Command) { - (Button { core, desktop }, app::Command::none()) + (Self { core, desktop }, app::Command::none()) } fn core(&self) -> &cosmic::app::Core {