summaryrefslogtreecommitdiffstats
path: root/src/utils.rs
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2022-12-05 15:31:12 +0100
committerqkzk <qu3nt1n@gmail.com>2022-12-05 15:31:12 +0100
commit93d408b8b0860eda8bd52ccdd088bc3da36803cf (patch)
treedcee5210b8f9a12ed7cc37c044d8fd5401e40597 /src/utils.rs
parentd0d34172f6e1646e7ff16c8361a3a9d0df021395 (diff)
Diffstat (limited to 'src/utils.rs')
-rw-r--r--src/utils.rs15
1 files changed, 6 insertions, 9 deletions
diff --git a/src/utils.rs b/src/utils.rs
index 51b1c01..8068b2c 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -1,4 +1,4 @@
-use std::path::PathBuf;
+use std::path::Path;
use std::sync::Arc;
use sysinfo::{Disk, DiskExt};
@@ -17,16 +17,13 @@ pub fn init_term() -> FmResult<Term> {
Ok(term)
}
-fn disk_used_by_path<'a>(disks: &'a [Disk], path: &PathBuf) -> Option<&'a Disk> {
+fn disk_used_by_path<'a>(disks: &'a [Disk], path: &Path) -> Option<&'a Disk> {
let mut disks: Vec<&Disk> = disks.iter().collect();
disks.sort_by_key(|disk| disk.mount_point().as_os_str().len());
disks.reverse();
- for disk in disks {
- if path.starts_with(disk.mount_point()) {
- return Some(disk);
- };
- }
- None
+ disks
+ .into_iter()
+ .find(|&disk| path.starts_with(disk.mount_point()))
}
fn disk_space_used(disk: Option<&Disk>) -> String {
@@ -36,7 +33,7 @@ fn disk_space_used(disk: Option<&Disk>) -> String {
}
}
-pub fn disk_space(disks: &[Disk], path: &PathBuf) -> String {
+pub fn disk_space(disks: &[Disk], path: &Path) -> String {
if path.as_os_str().is_empty() {
return "".to_owned();
}