Handle flatten + deserialize_with

This commit is contained in:
David Tolnay 2018-05-01 22:25:06 -07:00
parent 47a4ffbd31
commit cb2b92f828
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 12 additions and 1 deletions

View File

@ -2279,8 +2279,12 @@ fn deserialize_map(
.filter(|&&(field, _)| field.attrs.flatten())
.map(|&(field, ref name)| {
let field_ty = field.ty;
let func = match field.attrs.deserialize_with() {
None => quote!(_serde::de::Deserialize::deserialize),
Some(path) => quote!(#path),
};
quote! {
let #name: #field_ty = try!(_serde::de::Deserialize::deserialize(
let #name: #field_ty = try!(#func(
_serde::private::de::FlatMapDeserializer(
&mut __collect,
_serde::export::PhantomData)));

View File

@ -492,6 +492,13 @@ fn test_gen() {
}
assert_ser::<UntaggedVariantWith>();
#[derive(Serialize, Deserialize)]
struct FlattenWith {
#[serde(flatten, serialize_with = "ser_x", deserialize_with = "de_x")]
x: X,
}
assert::<FlattenWith>();
#[derive(Serialize, Deserialize)]
struct StaticStrStruct<'a> {
a: &'a str,