From 68c849066f99c245f6a3c80978cd3d26dfd3538c Mon Sep 17 00:00:00 2001 From: sxyazi Date: Fri, 25 Aug 2023 14:52:17 +0800 Subject: [PATCH] .. --- core/src/files/files.rs | 55 ++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/core/src/files/files.rs b/core/src/files/files.rs index b500de72..f79450a6 100644 --- a/core/src/files/files.rs +++ b/core/src/files/files.rs @@ -1,9 +1,4 @@ -use std::{ - cmp::Ordering, - collections::BTreeMap, - ops::{Deref, DerefMut}, - path::{Path, PathBuf}, -}; +use std::{cmp::Ordering, collections::BTreeMap, ops::{Deref, DerefMut}, path::{Path, PathBuf}}; use anyhow::Result; use config::{manager::SortBy, MANAGER}; @@ -13,14 +8,18 @@ use tokio::fs; use super::File; pub struct Files { - items: IndexMap, - pub sort: FilesSort, + items: IndexMap, + pub sort: FilesSort, pub show_hidden: bool, } impl Default for Files { fn default() -> Self { - Self { items: Default::default(), sort: Default::default(), show_hidden: MANAGER.show_hidden } + Self { + items: Default::default(), + sort: Default::default(), + show_hidden: MANAGER.show_hidden, + } } } @@ -123,21 +122,13 @@ impl Files { if promote != Ordering::Equal { promote } else { - if reverse { - b.cmp(&a) - } else { - a.cmp(&b) - } + if reverse { b.cmp(&a) } else { a.cmp(&b) } } } #[inline] fn promote(a: &File, b: &File, dir_first: bool) -> Ordering { - if dir_first { - b.meta.is_dir().cmp(&a.meta.is_dir()) - } else { - Ordering::Equal - } + if dir_first { b.meta.is_dir().cmp(&a.meta.is_dir()) } else { Ordering::Equal } } let reverse = self.sort.reverse; @@ -172,27 +163,27 @@ impl Files { impl Deref for Files { type Target = IndexMap; - fn deref(&self) -> &Self::Target { - &self.items - } + fn deref(&self) -> &Self::Target { &self.items } } impl DerefMut for Files { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.items - } + fn deref_mut(&mut self) -> &mut Self::Target { &mut self.items } } #[derive(PartialEq)] pub struct FilesSort { - pub by: SortBy, - pub reverse: bool, + pub by: SortBy, + pub reverse: bool, pub dir_first: bool, } impl Default for FilesSort { fn default() -> Self { - Self { by: MANAGER.sort_by, reverse: MANAGER.sort_reverse, dir_first: MANAGER.sort_dir_first } + Self { + by: MANAGER.sort_by, + reverse: MANAGER.sort_reverse, + dir_first: MANAGER.sort_dir_first, + } } } @@ -217,12 +208,8 @@ impl FilesOp { } #[inline] - pub fn read_empty(path: &Path) -> Self { - Self::Read(path.to_path_buf(), BTreeMap::new()) - } + pub fn read_empty(path: &Path) -> Self { Self::Read(path.to_path_buf(), BTreeMap::new()) } #[inline] - pub fn search_empty(path: &Path) -> Self { - Self::Search(path.to_path_buf(), BTreeMap::new()) - } + pub fn search_empty(path: &Path) -> Self { Self::Search(path.to_path_buf(), BTreeMap::new()) } }