From 8616b0780933888870bae8ac66df6eefaa08c017 Mon Sep 17 00:00:00 2001 From: Lutsai Aleksandr Date: Mon, 16 Dec 2024 21:58:48 +0300 Subject: [PATCH] linter fixes --- src/drives.rs | 23 ++++++----------------- src/main.rs | 23 +++++------------------ 2 files changed, 11 insertions(+), 35 deletions(-) diff --git a/src/drives.rs b/src/drives.rs index 56f0acf..2bf21a3 100644 --- a/src/drives.rs +++ b/src/drives.rs @@ -1,11 +1,5 @@ -use std::{ - collections::HashMap, - ffi::{OsStr, OsString}, - os::unix::ffi::{OsStrExt, OsStringExt}, - sync::{Arc, Mutex}, -}; - use crate::mountpoints; +use std::collections::HashMap; #[derive(Debug, Clone)] pub struct Block { @@ -36,10 +30,10 @@ pub async fn collect_drives_from_udisk() -> udisks2::Result> { .into_iter() .flatten() .filter_map(|(object_path, _)| { - let Ok(obj) = client.object(object_path.clone()) else { - return None; - }; - Some((object_path, obj)) + client + .object(object_path.clone()) + .ok() + .map(|obj| (object_path, obj)) }); for (path, i) in objects { @@ -106,7 +100,7 @@ pub async fn collect_all() -> udisks2::Result> { for i in mounts { let block = drives .iter_mut() - .find(|d| d.blocks.iter().find(|b| b.dev == i.dev).is_some()) + .find(|d| d.blocks.iter().any(|b| b.dev == i.dev)) .and_then(|d| d.blocks.iter_mut().find(|b| b.dev == i.dev)); if let Some(block) = block { block.mount = i.path; @@ -133,7 +127,6 @@ pub async fn collect_all() -> udisks2::Result> { } pub async fn mount(block: &Block) -> udisks2::Result<()> { - let mut drives: Vec = Vec::new(); let client = udisks2::Client::new().await?; client @@ -143,13 +136,10 @@ pub async fn mount(block: &Block) -> udisks2::Result<()> { .mount(HashMap::new()) .await?; - // client.part - Ok(()) } pub async fn unmount(block: &Block) -> udisks2::Result<()> { - let mut drives: Vec = Vec::new(); let client = udisks2::Client::new().await?; client @@ -158,7 +148,6 @@ pub async fn unmount(block: &Block) -> udisks2::Result<()> { .await? .unmount(HashMap::new()) .await?; - // client.part Ok(()) } diff --git a/src/main.rs b/src/main.rs index f4fbbad..870f805 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,21 +1,13 @@ mod drives; mod mountpoints; -use std::{ - ffi::{OsStr, OsString}, - io::stderr, - os::unix::ffi::{OsStrExt, OsStringExt}, - sync::Arc, - time::Duration, -}; +use std::{io::stderr, sync::Arc, time::Duration}; use crossterm::{ event::{Event, EventStream, KeyCode, KeyEventKind}, execute, terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}, }; -use drives::Drive; -use mountpoints::MountPoint; use ratatui::{ layout::{Alignment, Constraint, Layout}, prelude::CrosstermBackend, @@ -29,12 +21,6 @@ use ratatui::{ use tokio::sync::Mutex; use tokio_stream::StreamExt; -enum Command { - None, - Mount(String), - Umount(String), -} - #[tokio::main] async fn main() -> udisks2::Result<()> { enable_raw_mode().unwrap(); @@ -134,9 +120,10 @@ fn draw( i.dev.clone(), i.label.clone(), i.mount.clone().unwrap_or_default(), - match i.mounted { - true => "M".to_owned(), - false => "O".to_owned(), + if i.mounted { + "M".to_owned() + } else { + "O".to_owned() }, ]) });