use std::str::FromStr;
wrapper_lite::wrapper!(
#[wrapper_impl(Debug)]
#[wrapper_impl(AsRef)]
#[wrapper_impl(Deref)]
#[wrapper_impl(From)]
#[derive(Clone, PartialEq, Eq, Hash)]
pub struct Uri(http::Uri);
);
impl FromStr for Uri {
type Err = http::uri::InvalidUri;
fn from_str(s: &str) -> Result<Self, Self::Err> {
s.parse().map(Self::const_from)
}
}
impl serde::Serialize for Uri {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(&self.to_string())
}
}
impl<'de> serde::Deserialize<'de> for Uri {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
<&str>::deserialize(deserializer)?
.parse()
.map(Self::const_from)
.map_err(serde::de::Error::custom)
}
}
wrapper_lite::wrapper!(
#[wrapper_impl(Debug)]
#[wrapper_impl(AsRef)]
#[wrapper_impl(Deref)]
#[wrapper_impl(From)]
#[derive(Clone, PartialEq, Eq, Hash)]
pub struct Proxy(ureq::Proxy);
);
impl FromStr for Proxy {
type Err = ureq::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
ureq::Proxy::new(s).map(Self::const_from)
}
}
impl serde::Serialize for Proxy {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(&self.uri().to_string())
}
}
impl<'de> serde::Deserialize<'de> for Proxy {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
ureq::Proxy::new(<&str>::deserialize(deserializer)?)
.map(Self::const_from)
.map_err(serde::de::Error::custom)
}
}