Pair serialize_with and deserialize_with into one attribute

This commit is contained in:
David Tolnay
2017-02-14 17:36:50 -08:00
parent 090c8a7049
commit f500db6e91
2 changed files with 27 additions and 3 deletions
+12
View File
@@ -453,6 +453,18 @@ impl Field {
}
}
// Parse `#[serde(with="...")]`
MetaItem(NameValue(ref name, ref lit)) if name == "with" => {
if let Ok(path) = parse_lit_into_path(cx, name.as_ref(), lit) {
let mut ser_path = path.clone();
ser_path.segments.push("serialize".into());
serialize_with.set(ser_path);
let mut de_path = path;
de_path.segments.push("deserialize".into());
deserialize_with.set(de_path);
}
}
// Parse `#[serde(bound="D: Serialize")]`
MetaItem(NameValue(ref name, ref lit)) if name == "bound" => {
if let Ok(where_predicates) =