Eliminate unnecessary braces in wrap_deserialize_variant_with

This commit is contained in:
David Tolnay 2018-04-12 23:48:38 -07:00
parent 202c10147e
commit 1157ac0118
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -2600,36 +2600,28 @@ fn wrap_deserialize_variant_with(
let unwrap_fn = match variant.style {
Style::Struct if variant.fields.len() == 1 => {
let field_ident = variant.fields[0].ident.unwrap();
quote!({
|__wrap| {
#this::#variant_ident { #field_ident: __wrap.value }
}
})
quote! {
|__wrap| #this::#variant_ident { #field_ident: __wrap.value }
}
}
Style::Struct => {
let field_idents = variant
.fields
.iter()
.map(|field| field.ident.as_ref().unwrap());
quote!({
|__wrap| {
#this::#variant_ident { #(#field_idents: __wrap.value.#field_access),* }
}
})
quote! {
|__wrap| #this::#variant_ident { #(#field_idents: __wrap.value.#field_access),* }
}
}
Style::Tuple => quote!({
|__wrap| {
#this::#variant_ident(#(__wrap.value.#field_access),*)
}
}),
Style::Newtype => quote!({
|__wrap| {
#this::#variant_ident(__wrap.value)
}
}),
Style::Unit => quote!({
|__wrap| { #this::#variant_ident }
}),
Style::Tuple => quote! {
|__wrap| #this::#variant_ident(#(__wrap.value.#field_access),*)
},
Style::Newtype => quote! {
|__wrap| #this::#variant_ident(__wrap.value)
},
Style::Unit => quote! {
|__wrap| #this::#variant_ident
},
};
(wrapper, wrapper_ty, unwrap_fn)