use url::Url;
pub trait IntoUrl {
fn into_url(self) -> crate::Result<Url>;
fn as_str(&self) -> &str;
}
impl IntoUrl for Url {
fn into_url(self) -> crate::Result<Url> {
if self.has_host() {
Ok(self)
} else {
Err(crate::Error::InvalidUrl(self))
}
}
fn as_str(&self) -> &str {
self.as_ref()
}
}
impl IntoUrl for &str {
fn into_url(self) -> crate::Result<Url> {
Ok(Url::parse(self)?)
}
fn as_str(&self) -> &str {
self
}
}
impl IntoUrl for &String {
fn into_url(self) -> crate::Result<Url> {
(&**self).into_url()
}
fn as_str(&self) -> &str {
self
}
}
impl IntoUrl for String {
fn into_url(self) -> crate::Result<Url> {
(&*self).into_url()
}
fn as_str(&self) -> &str {
self
}
}