use 'Self' to refer to own type

This commit is contained in:
daniel.eades 2023-11-16 18:32:31 +00:00 committed by Ashley Wulber
parent a88cbad37f
commit b9723dd5e0
15 changed files with 48 additions and 54 deletions

View file

@ -108,7 +108,7 @@ impl DockItem {
rectangle_tracker: Option<&RectangleTracker<u32>>,
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<cosmic::app::Message<Self::Message>>) {
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()

View file

@ -26,7 +26,7 @@ pub struct AppListConfig {
impl AppListConfig {
// TODO async?
/// load config with the provided name
pub fn load() -> anyhow::Result<AppListConfig> {
pub fn load() -> anyhow::Result<Self> {
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))
}

View file

@ -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<Message>) {
fn init(core: cosmic::app::Core, _flags: ()) -> (Self, Command<Message>) {
(
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
}
}

View file

@ -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<PulseServer, PulseServerError<'static>> {
pub fn connect() -> Result<Self, PulseServerError<'static>> {
// 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()),

View file

@ -162,7 +162,7 @@ impl cosmic::Application for CosmicBatteryApplet {
cosmic::iced::Command<cosmic::app::Message<Self::Message>>,
) {
(
CosmicBatteryApplet {
Self {
core,
icon_name: "battery-symbolic".to_string(),
display_icon_name: "display-brightness-symbolic".to_string(),

View file

@ -75,7 +75,7 @@ impl cosmic::Application for CosmicBluetoothApplet {
_flags: Self::Flags,
) -> (Self, iced::Command<cosmic::app::Message<Self::Message>>) {
(
CosmicBluetoothApplet {
Self {
core,
icon_name: "bluetooth-symbolic".to_string(),
..Default::default()

View file

@ -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<cosmic::app::Message<Self::Message>>) {
let window = Window {
let window = Self {
core,
..Default::default()
};

View file

@ -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<AccessPoint> 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<Message>) {
(
CosmicNetworkApplet {
Self {
core,
icon_name: "network-offline-symbolic".to_string(),
..Default::default()

View file

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

View file

@ -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,

View file

@ -93,9 +93,9 @@ impl cosmic::Application for Power {
&mut self.core
}
fn init(core: cosmic::app::Core, _flags: ()) -> (Power, Command<Message>) {
fn init(core: cosmic::app::Core, _flags: ()) -> (Self, Command<Message>) {
(
Power {
Self {
core,
icon_name: "system-shutdown-symbolic".to_string(),
..Default::default()

View file

@ -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,

View file

@ -60,7 +60,7 @@ impl cosmic::Application for Window {
_flags: Self::Flags,
) -> (Self, cosmic::iced::Command<app::Message<Self::Message>>) {
(
Window {
Self {
core,
popup: None,
id_ctr: 0,

View file

@ -54,7 +54,7 @@ impl cosmic::Application for IcedWorkspacesApplet {
cosmic::iced::Command<cosmic::app::Message<Self::Message>>,
) {
(
IcedWorkspacesApplet {
Self {
layout: match &core.applet.anchor {
PanelAnchor::Left | PanelAnchor::Right => Layout::Column,
PanelAnchor::Top | PanelAnchor::Bottom => Layout::Row,

View file

@ -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<Msg>) {
(Button { core, desktop }, app::Command::none())
(Self { core, desktop }, app::Command::none())
}
fn core(&self) -> &cosmic::app::Core {