From 1ffd464c210805c66cecf0507386bc1940243e2b Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Sun, 10 Dec 2023 16:32:17 +0000 Subject: [PATCH] use 'Self' keyword to refer to own type (clippy::use_self) --- examples/application/src/main.rs | 10 +++++----- examples/cosmic/src/window.rs | 10 +++++----- examples/cosmic/src/window/demo.rs | 18 +++++++++--------- examples/cosmic/src/window/desktop.rs | 4 ++-- examples/multi-window/src/window.rs | 2 +- examples/open-dialog/src/main.rs | 2 +- src/widget/text_input/value.rs | 2 +- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/examples/application/src/main.rs b/examples/application/src/main.rs index a84eca1c..57b1347d 100644 --- a/examples/application/src/main.rs +++ b/examples/application/src/main.rs @@ -19,10 +19,10 @@ pub enum Page { impl Page { const fn as_str(self) -> &'static str { match self { - Page::Page1 => "Page 1", - Page::Page2 => "Page 2", - Page::Page3 => "Page 3", - Page::Page4 => "Page 4", + Self::Page1 => "Page 1", + Self::Page2 => "Page 2", + Self::Page3 => "Page 3", + Self::Page4 => "Page 4", } } } @@ -94,7 +94,7 @@ impl cosmic::Application for App { nav_model.activate_position(0); - let mut app = App { core, nav_model }; + let mut app = Self { core, nav_model }; let command = app.update_title(); diff --git a/examples/cosmic/src/window.rs b/examples/cosmic/src/window.rs index b4016ea9..168bf683 100644 --- a/examples/cosmic/src/window.rs +++ b/examples/cosmic/src/window.rs @@ -135,9 +135,9 @@ impl Page { } impl Default for Page { - fn default() -> Page { + fn default() -> Self { //TODO: what should the default page be? - Page::Desktop(None) + Self::Desktop(None) } } @@ -214,8 +214,8 @@ pub enum Message { } impl From for Message { - fn from(page: Page) -> Message { - Message::Page(page) + fn from(page: Page) -> Self { + Self::Page(page) } } @@ -323,7 +323,7 @@ impl Application for Window { type Theme = Theme; fn new(_flags: ()) -> (Self, Command) { - let mut window = Window::default() + let mut window = Self::default() .nav_bar_toggled(true) .show_maximize(true) .show_minimize(true); diff --git a/examples/cosmic/src/window/demo.rs b/examples/cosmic/src/window/demo.rs index 6329dd31..f3f417c5 100644 --- a/examples/cosmic/src/window/demo.rs +++ b/examples/cosmic/src/window/demo.rs @@ -35,19 +35,19 @@ pub enum ThemeVariant { impl From<&ThemeType> for ThemeVariant { fn from(theme: &ThemeType) -> Self { match theme { - ThemeType::Light => ThemeVariant::Light, - ThemeType::Dark => ThemeVariant::Dark, - ThemeType::HighContrastDark => ThemeVariant::HighContrastDark, - ThemeType::HighContrastLight => ThemeVariant::HighContrastLight, - ThemeType::Custom(_) => ThemeVariant::Custom, - ThemeType::System(_) => ThemeVariant::System, + ThemeType::Light => Self::Light, + ThemeType::Dark => Self::Dark, + ThemeType::HighContrastDark => Self::HighContrastDark, + ThemeType::HighContrastLight => Self::HighContrastLight, + ThemeType::Custom(_) => Self::Custom, + ThemeType::System(_) => Self::System, } } } impl From for ThemeVariant { fn from(theme: ThemeType) -> Self { - ThemeVariant::from(&theme) + Self::from(&theme) } } @@ -118,8 +118,8 @@ pub struct State { } impl Default for State { - fn default() -> State { - State { + fn default() -> Self { + Self { checkbox_value: false, dropdown_selected: Some(0), dropdown_options: vec!["Option 1", "Option 2", "Option 3", "Option 4"], diff --git a/examples/cosmic/src/window/desktop.rs b/examples/cosmic/src/window/desktop.rs index 3b3858da..99cbe2db 100644 --- a/examples/cosmic/src/window/desktop.rs +++ b/examples/cosmic/src/window/desktop.rs @@ -42,8 +42,8 @@ pub enum Message { } impl From for Message { - fn from(page: Page) -> Message { - Message::Page(page) + fn from(page: Page) -> Self { + Self::Page(page) } } diff --git a/examples/multi-window/src/window.rs b/examples/multi-window/src/window.rs index 0b269cf7..e50dd5b5 100644 --- a/examples/multi-window/src/window.rs +++ b/examples/multi-window/src/window.rs @@ -43,7 +43,7 @@ impl cosmic::Application for MultiWindow { } fn init(core: Core, _input: Self::Flags) -> (Self, cosmic::app::Command) { - let windows = MultiWindow { + let windows = Self { windows: HashMap::from([( window::Id::MAIN, Window { diff --git a/examples/open-dialog/src/main.rs b/examples/open-dialog/src/main.rs index f14379fc..bf639197 100644 --- a/examples/open-dialog/src/main.rs +++ b/examples/open-dialog/src/main.rs @@ -68,7 +68,7 @@ impl cosmic::Application for App { /// Creates the application, and optionally emits command on initialize. fn init(core: Core, _input: Self::Flags) -> (Self, Command) { - let mut app = App { + let mut app = Self { core, open_sender: None, file_contents: String::new(), diff --git a/src/widget/text_input/value.rs b/src/widget/text_input/value.rs index b18ea2ca..a53ec97e 100644 --- a/src/widget/text_input/value.rs +++ b/src/widget/text_input/value.rs @@ -100,7 +100,7 @@ impl Value { } /// Inserts a bunch of graphemes at the given grapheme `index`. - pub fn insert_many(&mut self, index: usize, mut value: Value) { + pub fn insert_many(&mut self, index: usize, mut value: Self) { let _ = self .graphemes .splice(index..index, value.graphemes.drain(..));