diff --git a/src/lib.rs b/src/lib.rs index f60f76e81..8aff08af4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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}; @@ -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 { + Url::parse(s) + } +} + /// Display the serialization of this URL. impl fmt::Display for Url { #[inline]