Skip to content

Commit

Permalink
Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
rgwood committed Apr 27, 2024
1 parent e950853 commit d0a76e0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 7 additions & 9 deletions src/components/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@ impl<T> StatefulList<T> {

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<UnitWithStatus>) {
Expand Down Expand Up @@ -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) }),
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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))])
}

Expand All @@ -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)
})
Expand Down Expand Up @@ -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),
];
Expand Down
10 changes: 8 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;

Expand Down
6 changes: 3 additions & 3 deletions src/systemd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<Vec<UnitWithStatus>> {
pub async fn get_all_services(scope: Scope) -> Result<Vec<UnitWithStatus>> {
let start = std::time::Instant::now();

let mut units = vec![];
Expand Down

0 comments on commit d0a76e0

Please sign in to comment.