diff --git a/src/types/mod.rs b/src/types/mod.rs index a5e8750..0dcbbf0 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -12,6 +12,7 @@ pub use error::GitUrlParseError; use core::str; use std::fmt; +use url::Url; use getset::{CloneGetters, CopyGetters, Setters}; #[cfg(feature = "log")] @@ -140,6 +141,24 @@ impl<'url> GitUrl<'url> { } } +#[cfg(feature = "url")] +impl<'url> TryFrom<&GitUrl<'url>> for Url { + type Error = url::ParseError; + fn try_from(value: &GitUrl) -> Result { + // Since we don't fully implement any spec, we'll rely on the url crate + Url::parse(&value.url_compat_display()) + } +} + +#[cfg(feature = "url")] +impl<'url> TryFrom> for Url { + type Error = url::ParseError; + fn try_from(value: GitUrl) -> Result { + // Since we don't fully implement any spec, we'll rely on the url crate + Url::parse(&value.url_compat_display()) + } +} + impl<'url> GitUrl<'url> { /// Returns `GitUrl` after removing all user info values pub fn trim_auth(&self) -> GitUrl { @@ -325,7 +344,7 @@ impl<'url> GitUrl<'url> { #[cfg(feature = "url")] { // Since we don't fully implement any spec, we'll rely on the url crate - let _u = url::Url::parse(&self.url_compat_display())?; + let _u: Url = self.try_into()?; } Ok(())