Created
January 23, 2018 09:17
-
-
Save mitsuhiko/07a9ae67eae2b4cd03940e05cfb96516 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
impl Serialize for UpstreamDescriptor<'static> { | |
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | |
where | |
S: Serializer, | |
{ | |
serializer.serialize_str(&self.to_string()) | |
} | |
} | |
impl<'de> Deserialize<'de> for UpstreamDescriptor<'static> { | |
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | |
where | |
D: Deserializer<'de>, | |
{ | |
struct V; | |
impl<'de> Visitor<'de> for V { | |
type Value = UpstreamDescriptor<'static>; | |
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { | |
formatter.write_str("a sentry upstream url") | |
} | |
fn visit_str<E>(self, value: &str) -> Result<UpstreamDescriptor<'static>, E> | |
where | |
E: de::Error, | |
{ | |
value | |
.parse() | |
.map_err(|_| de::Error::invalid_value(de::Unexpected::Str(value), &self)) | |
} | |
} | |
deserializer.deserialize_str(V) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment