diff --git a/yazi-actor/src/mgr/create.rs b/yazi-actor/src/mgr/create.rs index 094e8007..d79341aa 100644 --- a/yazi-actor/src/mgr/create.rs +++ b/yazi-actor/src/mgr/create.rs @@ -53,7 +53,7 @@ impl Create { FilesOp::Deleting(parent.into(), [urn.into()].into()).emit(); provider::create(&new).await?; } else if let Some(parent) = new.parent() { - provider::create_dir_all(&parent).await.ok(); + provider::create_dir_all(parent).await.ok(); ok_or_not_found(provider::remove_file(&new).await)?; provider::create(&new).await?; } else { diff --git a/yazi-core/src/tab/selected.rs b/yazi-core/src/tab/selected.rs index fd607df9..284c30b8 100644 --- a/yazi-core/src/tab/selected.rs +++ b/yazi-core/src/tab/selected.rs @@ -275,16 +275,16 @@ mod tests { let child1 = url("/parent/child1"); let child2 = url("/parent/child2"); let child3 = url("/parent/child3"); - assert_eq!(3, s.add_same([&child1, &child2, &child3])); + assert_eq!(3, s.add_same([child1, child2, child3])); - assert!(s.remove(&child1)); + assert!(s.remove(child1)); assert_eq!(s.inner.len(), 2); assert!(!s.parents.is_empty()); - assert!(s.remove(&child2)); + assert!(s.remove(child2)); assert!(!s.parents.is_empty()); - assert!(s.remove(&child3)); + assert!(s.remove(child3)); assert!(s.inner.is_empty()); assert!(s.parents.is_empty()); } diff --git a/yazi-fs/src/path/clean.rs b/yazi-fs/src/path/clean.rs index 4c3250b7..3d893d78 100644 --- a/yazi-fs/src/path/clean.rs +++ b/yazi-fs/src/path/clean.rs @@ -8,10 +8,7 @@ pub fn clean_url<'a>(url: impl Into>) -> UrlBuf { clean_path_impl(&cow.loc(), cow.loc().base().count(), cow.loc().trail().count()); let loc = LocBuf::with(path, uri, urn).expect("Failed to create Loc from cleaned path"); - match cow { - UrlCow::Borrowed { scheme, .. } => UrlBuf { loc, scheme: scheme.into() }, - UrlCow::Owned { scheme, .. } => UrlBuf { loc, scheme }, - } + UrlBuf { loc, scheme: cow.into_scheme().into() } } fn clean_path_impl(path: &Path, base: usize, trail: usize) -> (PathBuf, usize, usize) { diff --git a/yazi-scheduler/src/file/file.rs b/yazi-scheduler/src/file/file.rs index f8eefbbf..95098cc1 100644 --- a/yazi-scheduler/src/file/file.rs +++ b/yazi-scheduler/src/file/file.rs @@ -77,7 +77,7 @@ impl File { }; let src = if task.relative { - path_relative_to(provider::canonicalize(&task.to.parent().unwrap()).await?.loc, &src)? + path_relative_to(provider::canonicalize(task.to.parent().unwrap()).await?.loc, &src)? } else { src }; diff --git a/yazi-shared/src/scheme/ref.rs b/yazi-shared/src/scheme/ref.rs index b7feebbc..341c774a 100644 --- a/yazi-shared/src/scheme/ref.rs +++ b/yazi-shared/src/scheme/ref.rs @@ -1,6 +1,6 @@ use crate::{pool::InternStr, scheme::Scheme}; -#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] +#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)] pub enum SchemeRef<'a> { #[default] Regular, diff --git a/yazi-shared/src/scheme/scheme.rs b/yazi-shared/src/scheme/scheme.rs index 01684997..cd010873 100644 --- a/yazi-shared/src/scheme/scheme.rs +++ b/yazi-shared/src/scheme/scheme.rs @@ -1,6 +1,8 @@ +use std::hash::{Hash, Hasher}; + use crate::{pool::Symbol, scheme::SchemeRef}; -#[derive(Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] +#[derive(Clone, Debug, Default, Eq, PartialEq)] pub enum Scheme { #[default] Regular, @@ -12,6 +14,10 @@ pub enum Scheme { Sftp(Symbol), } +impl Hash for Scheme { + fn hash(&self, state: &mut H) { self.as_ref().hash(state); } +} + impl Scheme { #[inline] pub fn as_ref(&self) -> SchemeRef<'_> { self.into() } diff --git a/yazi-shared/src/url/buf.rs b/yazi-shared/src/url/buf.rs index 48b6ac6a..13e4a4c0 100644 --- a/yazi-shared/src/url/buf.rs +++ b/yazi-shared/src/url/buf.rs @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize}; use crate::{loc::LocBuf, pool::Pool, scheme::{Scheme, SchemeRef}, url::{Components, Display, Encode, EncodeTilded, Uri, Url, UrlCow, Urn}}; -#[derive(Clone, Default, Eq, Ord, PartialOrd, PartialEq, Hash)] +#[derive(Clone, Default, Eq, Hash, PartialEq)] pub struct UrlBuf { pub loc: LocBuf, pub scheme: Scheme, diff --git a/yazi-shared/src/url/component.rs b/yazi-shared/src/url/component.rs index 528dd61a..fc1a73e5 100644 --- a/yazi-shared/src/url/component.rs +++ b/yazi-shared/src/url/component.rs @@ -2,7 +2,7 @@ use std::{borrow::Cow, ffi::{OsStr, OsString}, iter::FusedIterator, ops::Not, pa use crate::{loc::Loc, scheme::{Scheme, SchemeRef}, url::{Encode, Url, UrlBuf, UrlCow}}; -#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +#[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum Component<'a> { Scheme(SchemeRef<'a>), Prefix(PrefixComponent<'a>), diff --git a/yazi-shared/src/url/cow.rs b/yazi-shared/src/url/cow.rs index 6d315ca5..6f7def57 100644 --- a/yazi-shared/src/url/cow.rs +++ b/yazi-shared/src/url/cow.rs @@ -3,12 +3,12 @@ use std::{borrow::Cow, path::{Path, PathBuf}}; use anyhow::Result; use percent_encoding::percent_decode; -use crate::{IntoOsStr, loc::{Loc, LocBuf}, scheme::{Scheme, SchemeCow, SchemeRef}, url::{Components, Url, UrlBuf, Urn}}; +use crate::{IntoOsStr, loc::{Loc, LocBuf}, scheme::{SchemeCow, SchemeRef}, url::{Components, Url, UrlBuf, Urn}}; #[derive(Debug)] pub enum UrlCow<'a> { Borrowed { loc: Loc<'a>, scheme: SchemeCow<'a> }, - Owned { loc: LocBuf, scheme: Scheme }, + Owned { loc: LocBuf, scheme: SchemeCow<'a> }, } impl Default for UrlCow<'_> { @@ -26,7 +26,7 @@ impl<'a> From<&'a UrlBuf> for UrlCow<'a> { } impl From for UrlCow<'_> { - fn from(value: UrlBuf) -> Self { Self::Owned { loc: value.loc, scheme: value.scheme } } + fn from(value: UrlBuf) -> Self { Self::Owned { loc: value.loc, scheme: value.scheme.into() } } } impl<'a> From<&'a UrlCow<'a>> for Url<'a> { @@ -52,9 +52,9 @@ impl<'a> TryFrom<&'a [u8]> for UrlCow<'a> { (Cow::Borrowed(p), Some((uri, urn))) => { Self::Borrowed { loc: Loc::with(p, uri, urn)?, scheme } } - (Cow::Owned(p), None) => Self::Owned { loc: LocBuf::from(p), scheme: scheme.into() }, + (Cow::Owned(p), None) => Self::Owned { loc: LocBuf::from(p), scheme }, (Cow::Owned(p), Some((uri, urn))) => { - Self::Owned { loc: LocBuf::with(p, uri, urn)?, scheme: scheme.into() } + Self::Owned { loc: LocBuf::with(p, uri, urn)?, scheme } } }) } @@ -98,7 +98,7 @@ impl PartialEq for UrlCow<'_> { fn eq(&self, other: &UrlBuf) -> bool { self.as_url() == other.as_url() } } -impl UrlCow<'_> { +impl<'a> UrlCow<'a> { #[inline] pub fn loc(&self) -> Loc<'_> { match self { @@ -127,7 +127,15 @@ impl UrlCow<'_> { pub fn into_owned(self) -> UrlBuf { match self { UrlCow::Borrowed { loc, scheme } => UrlBuf { loc: loc.into(), scheme: scheme.into() }, - UrlCow::Owned { loc, scheme } => UrlBuf { loc, scheme }, + UrlCow::Owned { loc, scheme } => UrlBuf { loc, scheme: scheme.into() }, + } + } + + #[inline] + pub fn into_scheme(self) -> SchemeCow<'a> { + match self { + UrlCow::Borrowed { scheme, .. } => scheme, + UrlCow::Owned { scheme, .. } => scheme, } } diff --git a/yazi-shared/src/url/encode.rs b/yazi-shared/src/url/encode.rs index d3267202..e24e756f 100644 --- a/yazi-shared/src/url/encode.rs +++ b/yazi-shared/src/url/encode.rs @@ -9,8 +9,8 @@ pub struct Encode<'a> { scheme: SchemeRef<'a>, } -impl<'a> From<&'a Url<'a>> for Encode<'a> { - fn from(url: &'a Url<'a>) -> Self { Self::new(url.loc, url.scheme) } +impl<'a> From> for Encode<'a> { + fn from(url: Url<'a>) -> Self { Self::new(url.loc, url.scheme) } } impl<'a> From<&'a UrlBuf> for Encode<'a> { @@ -78,10 +78,6 @@ pub struct EncodeTilded<'a> { scheme: SchemeRef<'a>, } -impl<'a> From<&'a Url<'a>> for EncodeTilded<'a> { - fn from(url: &'a Url<'a>) -> Self { Self { loc: url.loc, scheme: url.scheme } } -} - impl<'a> From<&'a UrlBuf> for EncodeTilded<'a> { fn from(url: &'a UrlBuf) -> Self { Self { loc: url.loc.as_loc(), scheme: url.scheme.as_ref() } } } diff --git a/yazi-shared/src/url/url.rs b/yazi-shared/src/url/url.rs index 8010f6ca..58f253cd 100644 --- a/yazi-shared/src/url/url.rs +++ b/yazi-shared/src/url/url.rs @@ -10,11 +10,6 @@ pub struct Url<'a> { pub scheme: SchemeRef<'a>, } -// TODO: remove -impl<'a> From<&'a Url<'a>> for Url<'a> { - fn from(value: &'a Url) -> Self { Self { loc: value.loc.as_loc(), scheme: value.scheme } } -} - impl<'a> From<&'a UrlBuf> for Url<'a> { fn from(value: &'a UrlBuf) -> Self { Self { loc: value.loc.as_loc(), scheme: value.scheme.as_ref() } @@ -41,7 +36,7 @@ impl Debug for Url<'_> { if self.scheme == SchemeRef::Regular { write!(f, "{}", self.loc.display()) } else { - write!(f, "{}{}", Encode::from(self), self.loc.display()) + write!(f, "{}{}", Encode::from(*self), self.loc.display()) } } } @@ -69,9 +64,6 @@ impl<'a> Url<'a> { #[inline] pub fn has_root(self) -> bool { self.loc.has_root() } - #[inline] - pub fn as_url(self) -> Url<'a> { self } - #[inline] pub fn to_owned(self) -> UrlBuf { self.into() }