From e9fc0a8db8ff531d27983e73ff7bd0b8bae9d63d Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Fri, 6 Dec 2019 01:42:39 +0900 Subject: [PATCH 1/2] impl TryFrom<'a str> for Url Signed-off-by: Yoshua Wuyts --- Cargo.toml | 3 +++ src/lib.rs | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 1299f2c05..a01a09e69 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,9 @@ harness = false [lib] test = false +[features] +try_from = [] + [dev-dependencies] rustc-test = "0.3" serde_json = "1.0" diff --git a/src/lib.rs b/src/lib.rs index d60935c29..d633287cb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -130,6 +130,9 @@ use std::ops::{Range, RangeFrom, RangeTo}; use std::path::{Path, PathBuf}; use std::str; +#[cfg(feature = "try_from")] +use std::convert::TryFrom; + pub use host::Host; pub use origin::{OpaqueOrigin, Origin}; pub use parser::{ParseError, SyntaxViolation}; @@ -2228,6 +2231,15 @@ impl str::FromStr for Url { } } +#[cfg(feature = "try_from")] +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] From 2f87fabb01013f39e063f406e452dcb00e062cb6 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Fri, 10 Jan 2020 12:17:40 +0100 Subject: [PATCH 2/2] disable feature flag url now requires Rust 1.36 which means a feature flag is now redundant. --- Cargo.toml | 3 --- src/lib.rs | 2 -- 2 files changed, 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a01a09e69..1299f2c05 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,9 +30,6 @@ harness = false [lib] test = false -[features] -try_from = [] - [dev-dependencies] rustc-test = "0.3" serde_json = "1.0" diff --git a/src/lib.rs b/src/lib.rs index d633287cb..43ba30f9b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -130,7 +130,6 @@ use std::ops::{Range, RangeFrom, RangeTo}; use std::path::{Path, PathBuf}; use std::str; -#[cfg(feature = "try_from")] use std::convert::TryFrom; pub use host::Host; @@ -2231,7 +2230,6 @@ impl str::FromStr for Url { } } -#[cfg(feature = "try_from")] impl<'a> TryFrom<&'a str> for Url { type Error = ParseError;