From cfe35cc691c590b6db893fcd8ba7f3c78b1786f4 Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Thu, 13 Jun 2024 21:13:28 +0800 Subject: [PATCH] Format files Signed-off-by: Xuanwo --- yazi-config/src/lib.rs | 3 +- yazi-config/src/schemes/schemes.rs | 11 ++-- yazi-shared/src/fs/file.rs | 40 ++++--------- yazi-shared/src/fs/schemes.rs | 7 ++- yazi-shared/src/fs/url.rs | 94 ++++++++---------------------- 5 files changed, 47 insertions(+), 108 deletions(-) diff --git a/yazi-config/src/lib.rs b/yazi-config/src/lib.rs index 4dc717d6..5b0a1615 100644 --- a/yazi-config/src/lib.rs +++ b/yazi-config/src/lib.rs @@ -19,13 +19,14 @@ pub mod theme; mod validation; pub mod which; -use crate::schemes::Schemes; pub use layout::*; pub(crate) use pattern::*; pub(crate) use preset::*; pub use priority::*; use yazi_shared::fs::SCHEMES; +use crate::schemes::Schemes; + static MERGED_YAZI: RoCell = RoCell::new(); static MERGED_KEYMAP: RoCell = RoCell::new(); static MERGED_THEME: RoCell = RoCell::new(); diff --git a/yazi-config/src/schemes/schemes.rs b/yazi-config/src/schemes/schemes.rs index 615c7600..841f2398 100644 --- a/yazi-config/src/schemes/schemes.rs +++ b/yazi-config/src/schemes/schemes.rs @@ -1,6 +1,7 @@ +use std::collections::HashMap; + use anyhow::Result; use serde::{Deserialize, Deserializer}; -use std::collections::HashMap; use crate::MERGED_YAZI; @@ -11,9 +12,7 @@ pub struct Schemes { } impl Default for Schemes { - fn default() -> Self { - toml::from_str(&MERGED_YAZI).unwrap() - } + fn default() -> Self { toml::from_str(&MERGED_YAZI).unwrap() } } impl Schemes { @@ -47,8 +46,8 @@ impl<'de> Deserialize<'de> for Schemes { /// Scheme in configuration file. #[derive(Debug, Deserialize)] pub struct Scheme { - pub name: String, + pub name: String, #[serde(rename = "type")] - pub typ: String, + pub typ: String, pub config: HashMap, } diff --git a/yazi-shared/src/fs/file.rs b/yazi-shared/src/fs/file.rs index 9156a39f..4488c4c4 100644 --- a/yazi-shared/src/fs/file.rs +++ b/yazi-shared/src/fs/file.rs @@ -1,31 +1,23 @@ -use std::ops::Add; -use std::time::{Duration, SystemTime}; -use std::{cell::Cell, ffi::OsStr, fs::Metadata, ops::Deref}; +use std::{cell::Cell, ffi::OsStr, fs::Metadata, ops::{Add, Deref}, time::{Duration, SystemTime}}; use anyhow::{anyhow, Result}; use tokio::fs; -use crate::fs::SCHEMES; -use crate::{ - fs::{Cha, ChaKind, Url}, - theme::IconCache, -}; +use crate::{fs::{Cha, ChaKind, Url, SCHEMES}, theme::IconCache}; #[derive(Clone, Debug, Default)] pub struct File { - pub url: Url, - pub cha: Cha, + pub url: Url, + pub cha: Cha, pub link_to: Option, - pub icon: Cell, + pub icon: Cell, } impl Deref for File { type Target = Cha; #[inline] - fn deref(&self) -> &Self::Target { - &self.cha - } + fn deref(&self) -> &Self::Target { &self.cha } } impl File { @@ -102,30 +94,20 @@ impl File { } #[inline] - pub fn from_dummy(url: &Url) -> Self { - Self { url: url.to_owned(), ..Default::default() } - } + pub fn from_dummy(url: &Url) -> Self { Self { url: url.to_owned(), ..Default::default() } } } impl File { // --- Url #[inline] - pub fn url(&self) -> Url { - self.url.clone() - } + pub fn url(&self) -> Url { self.url.clone() } #[inline] - pub fn name(&self) -> Option<&OsStr> { - self.url.file_name() - } + pub fn name(&self) -> Option<&OsStr> { self.url.file_name() } #[inline] - pub fn stem(&self) -> Option<&OsStr> { - self.url.file_stem() - } + pub fn stem(&self) -> Option<&OsStr> { self.url.file_stem() } #[inline] - pub fn parent(&self) -> Option { - self.url.parent_url() - } + pub fn parent(&self) -> Option { self.url.parent_url() } } diff --git a/yazi-shared/src/fs/schemes.rs b/yazi-shared/src/fs/schemes.rs index d9b548bd..84954d46 100644 --- a/yazi-shared/src/fs/schemes.rs +++ b/yazi-shared/src/fs/schemes.rs @@ -1,8 +1,9 @@ -use crate::RoCell; +use std::{collections::HashMap, str::FromStr}; + use anyhow::{anyhow, Result}; use opendal::Operator; -use std::collections::HashMap; -use std::str::FromStr; + +use crate::RoCell; /// SCHEMES is the read only cell of schemes that already loaded. pub static SCHEMES: RoCell = RoCell::new(); diff --git a/yazi-shared/src/fs/url.rs b/yazi-shared/src/fs/url.rs index 8a1bc752..f30cc287 100644 --- a/yazi-shared/src/fs/url.rs +++ b/yazi-shared/src/fs/url.rs @@ -1,9 +1,4 @@ -use std::{ - ffi::{OsStr, OsString}, - fmt::{Debug, Display, Formatter}, - ops::{Deref, DerefMut}, - path::{Path, PathBuf}, -}; +use std::{ffi::{OsStr, OsString}, fmt::{Debug, Display, Formatter}, ops::{Deref, DerefMut}, path::{Path, PathBuf}}; use percent_encoding::{percent_decode_str, percent_encode, AsciiSet, CONTROLS}; use serde::{Deserialize, Serialize}; @@ -13,8 +8,8 @@ const ENCODE_SET: &AsciiSet = &CONTROLS.add(b'#'); #[derive(Clone, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct Url { scheme: UrlScheme, - path: PathBuf, - frag: String, + path: PathBuf, + frag: String, } #[derive(Clone, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] @@ -29,51 +24,35 @@ pub enum UrlScheme { impl Deref for Url { type Target = PathBuf; - fn deref(&self) -> &Self::Target { - &self.path - } + fn deref(&self) -> &Self::Target { &self.path } } impl DerefMut for Url { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.path - } + fn deref_mut(&mut self) -> &mut Self::Target { &mut self.path } } impl Debug for Url { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.path.display()) - } + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.path.display()) } } impl From for Url { - fn from(path: PathBuf) -> Self { - Self { path, ..Default::default() } - } + fn from(path: PathBuf) -> Self { Self { path, ..Default::default() } } } impl From<&PathBuf> for Url { - fn from(path: &PathBuf) -> Self { - Self::from(path.clone()) - } + fn from(path: &PathBuf) -> Self { Self::from(path.clone()) } } impl From<&Path> for Url { - fn from(path: &Path) -> Self { - Self::from(path.to_path_buf()) - } + fn from(path: &Path) -> Self { Self::from(path.to_path_buf()) } } impl From for Url { - fn from(path: String) -> Self { - Self::from(path.as_str()) - } + fn from(path: String) -> Self { Self::from(path.as_str()) } } impl From<&String> for Url { - fn from(path: &String) -> Self { - Self::from(path.as_str()) - } + fn from(path: &String) -> Self { Self::from(path.as_str()) } } impl From<&str> for Url { @@ -107,21 +86,15 @@ impl From<&str> for Url { } impl AsRef for Url { - fn as_ref(&self) -> &Url { - self - } + fn as_ref(&self) -> &Url { self } } impl AsRef for Url { - fn as_ref(&self) -> &Path { - &self.path - } + fn as_ref(&self) -> &Path { &self.path } } impl AsRef for Url { - fn as_ref(&self) -> &OsStr { - self.path.as_os_str() - } + fn as_ref(&self) -> &OsStr { self.path.as_os_str() } } impl Display for Url { @@ -175,9 +148,7 @@ impl Url { } #[inline] - pub fn into_os_string(self) -> OsString { - self.path.into_os_string() - } + pub fn into_os_string(self) -> OsString { self.path.into_os_string() } #[cfg(unix)] #[inline] @@ -189,14 +160,10 @@ impl Url { impl Url { // --- Scheme #[inline] - pub fn is_regular(&self) -> bool { - self.scheme == UrlScheme::Regular - } + pub fn is_regular(&self) -> bool { self.scheme == UrlScheme::Regular } #[inline] - pub fn to_regular(&self) -> Self { - self.clone().into_regular() - } + pub fn to_regular(&self) -> Self { self.clone().into_regular() } #[inline] pub fn into_regular(mut self) -> Self { @@ -205,14 +172,10 @@ impl Url { } #[inline] - pub fn is_search(&self) -> bool { - self.scheme == UrlScheme::Search - } + pub fn is_search(&self) -> bool { self.scheme == UrlScheme::Search } #[inline] - pub fn to_search(&self, frag: String) -> Self { - self.clone().into_search(frag) - } + pub fn to_search(&self, frag: String) -> Self { self.clone().into_search(frag) } #[inline] pub fn into_search(mut self, frag: String) -> Self { @@ -222,14 +185,10 @@ impl Url { } #[inline] - pub fn is_archive(&self) -> bool { - self.scheme == UrlScheme::Archive - } + pub fn is_archive(&self) -> bool { self.scheme == UrlScheme::Archive } #[inline] - pub fn to_archive(&self) -> Self { - self.clone().into_archive() - } + pub fn to_archive(&self) -> Self { self.clone().into_archive() } #[inline] pub fn into_archive(mut self) -> Self { @@ -239,7 +198,8 @@ impl Url { /// Check and fetch remote scheme. /// - /// Returns None if current url is not remote, otherwise returns `Some(scheme)` + /// Returns None if current url is not remote, otherwise returns + /// `Some(scheme)` #[inline] pub fn is_remote(&self) -> Option<&str> { match &self.scheme { @@ -250,15 +210,11 @@ impl Url { // --- Path #[inline] - pub fn set_path(&mut self, path: PathBuf) { - self.path = path; - } + pub fn set_path(&mut self, path: PathBuf) { self.path = path; } // --- Frag #[inline] - pub fn frag(&self) -> &str { - &self.frag - } + pub fn frag(&self) -> &str { &self.frag } } impl From<&str> for UrlScheme {