diff --git a/src/lib.rs b/src/lib.rs index 4bd8ac5ee..367b20270 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,7 +20,6 @@ pub mod system_tools; pub mod tool_configuration; #[cfg(feature = "tui")] pub mod tui; -mod url_with_trailing_slash; pub mod used_variables; pub mod utils; pub mod variant_config; diff --git a/src/url_with_trailing_slash.rs b/src/url_with_trailing_slash.rs deleted file mode 100644 index 7cd677349..000000000 --- a/src/url_with_trailing_slash.rs +++ /dev/null @@ -1,82 +0,0 @@ -// copied from rattler-conda-types::utils::url_with_trailing_slash -// TODO: move to separate crate - -use std::{ - fmt::{Display, Formatter}, - ops::Deref, - str::FromStr, -}; - -use rattler_redaction::Redact; -use serde::{Deserialize, Deserializer, Serialize}; -use url::Url; - -/// A URL that always has a trailing slash. A trailing slash in a URL has -/// significance but users often forget to add it. This type is used to -/// normalize the use of the URL. -#[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize)] -#[serde(transparent)] -pub struct UrlWithTrailingSlash(Url); - -impl Deref for UrlWithTrailingSlash { - type Target = Url; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl AsRef for UrlWithTrailingSlash { - fn as_ref(&self) -> &Url { - &self.0 - } -} - -impl From for UrlWithTrailingSlash { - fn from(url: Url) -> Self { - let path = url.path(); - if path.ends_with('/') { - Self(url) - } else { - let mut url = url.clone(); - url.set_path(&format!("{path}/")); - Self(url) - } - } -} - -impl<'de> Deserialize<'de> for UrlWithTrailingSlash { - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - let url = Url::deserialize(deserializer)?; - Ok(url.into()) - } -} - -impl FromStr for UrlWithTrailingSlash { - type Err = url::ParseError; - - fn from_str(s: &str) -> Result { - Ok(Url::parse(s)?.into()) - } -} - -impl From for Url { - fn from(value: UrlWithTrailingSlash) -> Self { - value.0 - } -} - -impl Display for UrlWithTrailingSlash { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", &self.0) - } -} - -impl Redact for UrlWithTrailingSlash { - fn redact(self) -> Self { - UrlWithTrailingSlash(self.0.redact()) - } -}