Skip to content

Instantly share code, notes, and snippets.

@mitsuhiko
Created January 23, 2018 09:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitsuhiko/07a9ae67eae2b4cd03940e05cfb96516 to your computer and use it in GitHub Desktop.
Save mitsuhiko/07a9ae67eae2b4cd03940e05cfb96516 to your computer and use it in GitHub Desktop.
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