Skip to content

Commit

Permalink
impl TryFrom<'a str> for Url (#569)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshuawuyts authored Mar 9, 2020
1 parent f091d2b commit 2831475
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ use std::ops::{Range, RangeFrom, RangeTo};
use std::path::{Path, PathBuf};
use std::str;

use std::convert::TryFrom;

pub use host::Host;
pub use origin::{OpaqueOrigin, Origin};
pub use parser::{ParseError, SyntaxViolation};
Expand Down Expand Up @@ -2324,6 +2326,14 @@ impl str::FromStr for Url {
}
}

impl<'a> TryFrom<&'a str> for Url {
type Error = ParseError;

fn try_from(s: &'a str) -> Result<Self, Self::Error> {
Url::parse(s)
}
}

/// Display the serialization of this URL.
impl fmt::Display for Url {
#[inline]
Expand Down

0 comments on commit 2831475

Please sign in to comment.