mirror of
https://github.com/LemmyNet/activitypub-federation-rust
synced 2024-11-13 23:47:07 +00:00
simplify
This commit is contained in:
parent
d066cc9e13
commit
c5cec6cef6
1 changed files with 9 additions and 9 deletions
18
src/url.rs
18
src/url.rs
|
@ -32,15 +32,18 @@ impl Url {
|
||||||
pub fn domain(&self) -> &str {
|
pub fn domain(&self) -> &str {
|
||||||
self.0.domain().expect("has domain")
|
self.0.domain().expect("has domain")
|
||||||
}
|
}
|
||||||
|
fn new(value: url::Url) -> Result<Self, url::ParseError> {
|
||||||
|
if value.domain().is_none() {
|
||||||
|
return Err(url::ParseError::EmptyHost);
|
||||||
|
}
|
||||||
|
Ok(Url(value))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<url::Url> for Url {
|
impl TryFrom<url::Url> for Url {
|
||||||
type Error = url::ParseError;
|
type Error = url::ParseError;
|
||||||
fn try_from(value: url::Url) -> Result<Self, Self::Error> {
|
fn try_from(value: url::Url) -> Result<Self, Self::Error> {
|
||||||
if value.domain().is_none() {
|
Self::new(value)
|
||||||
return Err(url::ParseError::EmptyHost);
|
|
||||||
}
|
|
||||||
Ok(Url(value))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,11 +58,8 @@ impl FromStr for Url {
|
||||||
type Err = url::ParseError;
|
type Err = url::ParseError;
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
let url = url::Url::from_str(s)?;
|
let value = url::Url::from_str(s)?;
|
||||||
if url.domain().is_none() {
|
Self::new(value)
|
||||||
return Err(url::ParseError::EmptyHost);
|
|
||||||
}
|
|
||||||
Ok(Url(url))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue