diff --git a/src/app.rs b/src/app.rs index 9802387..15b19dc 100644 --- a/src/app.rs +++ b/src/app.rs @@ -57,7 +57,7 @@ impl App { self.home.lock().await.init(action_tx.clone())?; - let units = get_all_services(&self.scope) + let units = get_all_services(self.scope) .await .context("Unable to get services. Check that systemd is running and try running this tool with sudo.")?; self.home.lock().await.set_units(units); diff --git a/src/components/home.rs b/src/components/home.rs index ad6462b..c9cf90f 100644 --- a/src/components/home.rs +++ b/src/components/home.rs @@ -144,9 +144,7 @@ impl StatefulList { impl Home { pub fn new(scope: Scope) -> Self { - let mut ret = Self::default(); - ret.scope = scope; - ret + Self { scope, ..Default::default() } } pub fn set_units(&mut self, units: Vec) { @@ -584,7 +582,7 @@ impl Component for Home { Action::CopyUnitFilePath => { if let Some(selected) = self.filtered_units.selected() { if let Some(file_path) = &selected.file_path { - match clipboard_anywhere::set_clipboard(&file_path) { + match clipboard_anywhere::set_clipboard(file_path) { Ok(_) => return Some(Action::EnterMode(Mode::ServiceList)), Err(e) => return Some(Action::EnterError { err: format!("Error copying to clipboard: {}", e) }), } @@ -637,9 +635,9 @@ impl Component for Home { Action::RestartService(service_name) => self.restart_service(service_name), Action::RefreshServices => { let tx = self.action_tx.clone().unwrap(); - let scope = self.scope.clone(); + let scope = self.scope; tokio::spawn(async move { - let units = systemd::get_all_services(&scope) + let units = systemd::get_all_services(scope) .await .expect("Failed to get services. Check that systemd is running and try running this tool with sudo."); tx.send(Action::SetServices(units)).unwrap(); @@ -679,7 +677,7 @@ impl Component for Home { let search_panel = rects[0]; let main_panel = rects[1]; - fn colored_line<'a>(value: &'a str, color: Color) -> Line<'a> { + fn colored_line(value: &str, color: Color) -> Line { Line::from(vec![Span::styled(value, Style::default().fg(color))]) } @@ -706,7 +704,7 @@ impl Component for Home { .items .iter() .map(|i| { - let color = unit_color(&i); + let color = unit_color(i); let line = colored_line(i.short_name(), color); ListItem::new(line) }) @@ -781,7 +779,7 @@ impl Component for Home { let mut lines = vec![ colored_line(&i.description, Color::White), - colored_line(&scope, Color::White), + colored_line(scope, Color::White), colored_line(&i.load_state, load_color), line_color_string(active_state_value, active_color), ]; diff --git a/src/main.rs b/src/main.rs index af9c017..ee2a5f6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,9 +43,15 @@ async fn main() -> Result<()> { Some(Scope::All) => systemd::Scope::All, // So, WSL doesn't *really* support user services yet: https://github.com/microsoft/WSL/issues/8842 // Revisit this if that changes - None => if is_wsl::is_wsl() { systemd::Scope::Global } else { systemd::Scope::All }, + None => { + if is_wsl::is_wsl() { + systemd::Scope::Global + } else { + systemd::Scope::All + } + }, }; - + let mut app = App::new(scope)?; app.run().await?; diff --git a/src/systemd.rs b/src/systemd.rs index 26290ac..60df69e 100644 --- a/src/systemd.rs +++ b/src/systemd.rs @@ -5,7 +5,7 @@ use duct::cmd; use log::error; use tokio_util::sync::CancellationToken; use tracing::info; -use zbus::{proxy, Connection, zvariant}; +use zbus::{proxy, zvariant, Connection}; #[derive(Debug, Clone)] pub struct UnitWithStatus { @@ -64,7 +64,7 @@ impl UnitWithStatus { // TODO: should we have a non-allocating version of this? pub fn id(&self) -> UnitId { - UnitId { name: self.name.clone(), scope: self.scope.clone() } + UnitId { name: self.name.clone(), scope: self.scope } } // useful for updating without wiping out the file path @@ -96,7 +96,7 @@ pub enum Scope { } // this takes like 5-10 ms on 13th gen Intel i7 (scope=all) -pub async fn get_all_services(scope: &Scope) -> Result> { +pub async fn get_all_services(scope: Scope) -> Result> { let start = std::time::Instant::now(); let mut units = vec![];