diff --git a/src/attr.rs b/src/attr.rs index 35f0650..2781320 100644 --- a/src/attr.rs +++ b/src/attr.rs @@ -30,7 +30,10 @@ pub(crate) fn tag_type(attrs: &[Attribute], enumeration: &DataEnum) -> Result Result { for fields in enumeration.variants.iter().map(|v| &v.fields) { if let Fields::Unnamed(_) = fields { - return Err(Error::new_spanned(fields, - "enums containing tuple variants cannot be internally tagged")); + return Err(Error::new_spanned( + fields, + "enums containing tuple variants cannot be internally tagged", + )); } } Ok(TagType::Internal(tag)) } (Some(tag), Some(content)) => Ok(TagType::Adjacent { tag, content }), - _ => Err(Error::new_spanned(&attrs[0], "Invalid enum representation.")) + _ => Err(Error::new_spanned( + &attrs[0], + "Invalid enum representation.", + )), } } diff --git a/src/de.rs b/src/de.rs index bedf067..f00a0c4 100644 --- a/src/de.rs +++ b/src/de.rs @@ -12,7 +12,9 @@ pub fn derive(input: &DeriveInput, enumeration: &DataEnum) -> Result deserialize_external(input, enumeration), - TagType::Adjacent { tag, content } => deserialize_adjacent(input, enumeration, tag, content), + TagType::Adjacent { tag, content } => { + deserialize_adjacent(input, enumeration, tag, content) + } TagType::Internal(tag) => deserialize_internal(input, enumeration, tag), _ => Err(Error::new( Span::call_site(), @@ -33,13 +35,13 @@ struct EnumVariants { impl EnumVariants { fn new(ident: &Ident, enumeration: &DataEnum) -> Result { let (unit_variants, struct_variants): (Vec<_>, Vec<_>) = - enumeration.variants.iter().partition(|v| { - if let Fields::Unit = &v.fields { - true - } else { - false - } - }); + enumeration.variants.iter().partition(|v| { + if let Fields::Unit = &v.fields { + true + } else { + false + } + }); let struct_variant_names = struct_variants .iter() .cloned() @@ -51,9 +53,9 @@ impl EnumVariants { Ident::new( &format!("__{}_{}_Struct", ident, variant.ident), Span::call_site(), - ) + ) }) - .collect::>(); + .collect::>(); let structs = struct_variants .iter() .zip(struct_names.iter()) @@ -63,7 +65,10 @@ impl EnumVariants { .iter() .map(|variant| variant.ident.clone()) .collect::>(); - let unit_variant_idents = unit_variants.iter().map(|v| v.ident.clone()).collect::>(); + let unit_variant_idents = unit_variants + .iter() + .map(|v| v.ident.clone()) + .collect::>(); let unit_variant_names = unit_variants .iter() .cloned() @@ -80,7 +85,11 @@ impl EnumVariants { } } -pub fn deserialize_internal(input: &DeriveInput, enumeration: &DataEnum, tag: &str) -> Result { +pub fn deserialize_internal( + input: &DeriveInput, + enumeration: &DataEnum, + tag: &str, +) -> Result { let ident = &input.ident; let EnumVariants { struct_variant_names, @@ -171,7 +180,12 @@ pub fn deserialize_internal(input: &DeriveInput, enumeration: &DataEnum, tag: &s }) } -pub fn deserialize_adjacent(input: &DeriveInput, enumeration: &DataEnum, tag: &str, content: &str) -> Result { +pub fn deserialize_adjacent( + input: &DeriveInput, + enumeration: &DataEnum, + tag: &str, + content: &str, +) -> Result { let ident = &input.ident; let EnumVariants { struct_variant_names,