Format variant-skip message only if variant is skipped
This commit is contained in:
parent
2401ae61a8
commit
28d67f4172
@ -256,29 +256,19 @@ fn serialize_variant(
|
|||||||
let variant_ident = variant.ident.clone();
|
let variant_ident = variant.ident.clone();
|
||||||
let variant_name = variant.attrs.name().serialize_name();
|
let variant_name = variant.attrs.name().serialize_name();
|
||||||
|
|
||||||
let skipped_msg = format!("The enum variant {}::{} cannot be serialized",
|
|
||||||
type_ident, variant_ident);
|
|
||||||
let skipped_err = quote! {
|
|
||||||
Err(_serde::ser::Error::invalid_value(#skipped_msg))
|
|
||||||
};
|
|
||||||
|
|
||||||
if variant.attrs.skip_serializing() {
|
if variant.attrs.skip_serializing() {
|
||||||
match variant.style {
|
let skipped_msg = format!("The enum variant {}::{} cannot be serialized",
|
||||||
Style::Unit => {
|
type_ident, variant_ident);
|
||||||
quote! {
|
let skipped_err = quote! {
|
||||||
#type_ident::#variant_ident => #skipped_err,
|
Err(_serde::ser::Error::invalid_value(#skipped_msg))
|
||||||
}
|
};
|
||||||
},
|
let fields_pat = match variant.style {
|
||||||
Style::Newtype | Style::Tuple => {
|
Style::Unit => quote!(),
|
||||||
quote! {
|
Style::Newtype | Style::Tuple => quote!( (..) ),
|
||||||
#type_ident::#variant_ident(..) => #skipped_err,
|
Style::Struct => quote!( {..} ),
|
||||||
}
|
};
|
||||||
},
|
quote! {
|
||||||
Style::Struct => {
|
#type_ident::#variant_ident #fields_pat => #skipped_err,
|
||||||
quote! {
|
|
||||||
#type_ident::#variant_ident{..} => #skipped_err,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else { // variant wasn't skipped
|
} else { // variant wasn't skipped
|
||||||
match variant.style {
|
match variant.style {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user