Created
February 3, 2018 23:54
-
-
Save dherman/d21f0ee05422b97d377222c676963ee9 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
// examples of `deserialize_with` and `serialize_with` in serde | |
#[derive(Serialize, Deserialize, Eq, PartialEq)] | |
#[serde(untagged)] | |
pub enum Version { | |
#[serde(serialize_with = "serialize_public")] | |
#[serde(deserialize_with = "deserialize_public")] | |
Public(String) | |
} | |
fn serialize_public<S: serde::Serializer>(v: &String, s: S) -> Result<S::Ok, S::Error> { | |
s.serialize_str(&v[..]) | |
} | |
fn deserialize_public<'de, D: serde::Deserializer<'de>>(d: D) -> Result<String, D::Error> { | |
String::deserialize(d) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment