Added Serde Serialize/Deserialize traits

This commit is contained in:
Johan Verwey 2021-09-25 07:54:24 -07:00 committed by David Tolnay
parent 6ca43ce46f
commit b3ac95e814
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 10 additions and 0 deletions

View File

@ -21,6 +21,8 @@ pub fn expand_struct(strct: &Struct, actual_derives: &mut Option<TokenStream>) -
Trait::Ord => expanded.extend(struct_ord(strct, span)),
Trait::PartialEq => traits.push(quote_spanned!(span=> ::std::cmp::PartialEq)),
Trait::PartialOrd => expanded.extend(struct_partial_ord(strct, span)),
Trait::Serialize => traits.push(quote_spanned!(span=> serde::Serialize)),
Trait::Deserialize => traits.push(quote_spanned!(span=> serde::Deserialize)),
}
}
@ -66,6 +68,8 @@ pub fn expand_enum(enm: &Enum, actual_derives: &mut Option<TokenStream>) -> Toke
has_partial_eq = true;
}
Trait::PartialOrd => expanded.extend(enum_partial_ord(enm, span)),
Trait::Serialize => traits.push(quote_spanned!(span=> serde::Serialize)),
Trait::Deserialize => traits.push(quote_spanned!(span=> serde::Deserialize)),
}
}

View File

@ -19,6 +19,8 @@ pub enum Trait {
Ord,
PartialEq,
PartialOrd,
Serialize,
Deserialize,
}
impl Derive {
@ -34,6 +36,8 @@ impl Derive {
"Ord" => Trait::Ord,
"PartialEq" => Trait::PartialEq,
"PartialOrd" => Trait::PartialOrd,
"Serialize" => Trait::Serialize,
"Deserialize" => Trait::Deserialize,
_ => return None,
};
let span = ident.span();
@ -60,6 +64,8 @@ impl AsRef<str> for Trait {
Trait::Ord => "Ord",
Trait::PartialEq => "PartialEq",
Trait::PartialOrd => "PartialOrd",
Trait::Serialize => "Serialize",
Trait::Deserialize => "Deserialize",
}
}
}