Skip to content

Commit 2831475

Browse files
authored
impl TryFrom<'a str> for Url (#569)
1 parent f091d2b commit 2831475

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ use std::ops::{Range, RangeFrom, RangeTo};
130130
use std::path::{Path, PathBuf};
131131
use std::str;
132132

133+
use std::convert::TryFrom;
134+
133135
pub use host::Host;
134136
pub use origin::{OpaqueOrigin, Origin};
135137
pub use parser::{ParseError, SyntaxViolation};
@@ -2324,6 +2326,14 @@ impl str::FromStr for Url {
23242326
}
23252327
}
23262328

2329+
impl<'a> TryFrom<&'a str> for Url {
2330+
type Error = ParseError;
2331+
2332+
fn try_from(s: &'a str) -> Result<Self, Self::Error> {
2333+
Url::parse(s)
2334+
}
2335+
}
2336+
23272337
/// Display the serialization of this URL.
23282338
impl fmt::Display for Url {
23292339
#[inline]

0 commit comments

Comments
 (0)