diff --git a/yazi-shared/src/url/scheme.rs b/yazi-shared/src/url/scheme.rs index 9507103a..3a8bf357 100644 --- a/yazi-shared/src/url/scheme.rs +++ b/yazi-shared/src/url/scheme.rs @@ -1,3 +1,5 @@ +use std::fmt::Display; + use anyhow::bail; #[derive(Clone, Copy, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] @@ -21,3 +23,14 @@ impl TryFrom<&[u8]> for Scheme { }) } } + +impl Display for Scheme { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Scheme::Regular => write!(f, "regular"), + Scheme::Search => write!(f, "search"), + Scheme::SearchItem => write!(f, "search_item"), + Scheme::Archive => write!(f, "archive"), + } + } +} diff --git a/yazi-shared/src/url/url.rs b/yazi-shared/src/url/url.rs index 94f77cef..fcf1d115 100644 --- a/yazi-shared/src/url/url.rs +++ b/yazi-shared/src/url/url.rs @@ -89,10 +89,6 @@ impl TryFrom for Url { fn try_from(value: String) -> Result { value.as_bytes().try_into() } } -// impl From<&String> for Url { -// fn from(path: &String) -> Self { path.as_str().into() } -// } - impl AsRef for Url { fn as_ref(&self) -> &Url { self } } @@ -111,14 +107,9 @@ impl Display for Url { return write!(f, "{}", self.loc.display()); } - let scheme = match self.scheme { - Scheme::Regular | Scheme::SearchItem => unreachable!(), - Scheme::Search => "search://", - Scheme::Archive => "archive://", - }; - let path = percent_encode(self.loc.as_os_str().as_encoded_bytes(), ENCODE_SET); + let loc = percent_encode(self.loc.as_os_str().as_encoded_bytes(), ENCODE_SET); + write!(f, "{}://{loc}", self.scheme)?; - write!(f, "{scheme}{path}")?; if !self.frag.is_empty() { write!(f, "#{}", percent_encode(self.frag.as_encoded_bytes(), ENCODE_SET))?; }