Fix formatting

This commit is contained in:
Dirkjan Ochtman 2022-11-19 20:20:14 +01:00
parent 55c7c5db99
commit 0be3c92d27
2 changed files with 7 additions and 11 deletions

View File

@ -30,7 +30,6 @@ pub fn from_xml(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
struct ContainerMeta<'input> { struct ContainerMeta<'input> {
input: &'input DeriveInput, input: &'input DeriveInput,
ns: NamespaceMeta, ns: NamespaceMeta,
rename: Option<Literal>, rename: Option<Literal>,
rename_all: RenameRule, rename_all: RenameRule,
@ -161,7 +160,6 @@ impl VariantMeta {
for (item, span) in meta_items(&input.attrs) { for (item, span) in meta_items(&input.attrs) {
match item { match item {
MetaItem::Rename(lit) => rename = Some(lit.to_token_stream()), MetaItem::Rename(lit) => rename = Some(lit.to_token_stream()),
MetaItem::Attribute => { MetaItem::Attribute => {
return Err(syn::Error::new( return Err(syn::Error::new(
span, span,

View File

@ -26,39 +26,37 @@ pub fn to_xml(input: &syn::DeriveInput) -> proc_macro2::TokenStream {
} }
} }
#[rustfmt::skip]
fn serialize_enum( fn serialize_enum(
input: &syn::DeriveInput, input: &syn::DeriveInput,
data: &syn::DataEnum, data: &syn::DataEnum,
meta: ContainerMeta meta: ContainerMeta,
) -> TokenStream { ) -> TokenStream {
let ident = &input.ident; let ident = &input.ident;
let mut variants = TokenStream::new(); let mut variants = TokenStream::new();
for variant in data.variants.iter() { for variant in data.variants.iter() {
let v_ident = &variant.ident; let v_ident = &variant.ident;
let meta = match VariantMeta::from_variant(variant, &meta) { let meta = match VariantMeta::from_variant(variant, &meta) {
Ok(meta) => meta, Ok(meta) => meta,
Err(err) => return err.to_compile_error() Err(err) => return err.to_compile_error(),
}; };
let serialize_as = meta.serialize_as; let serialize_as = meta.serialize_as;
variants.extend(quote!(#ident::#v_ident => #serialize_as,)); variants.extend(quote!(#ident::#v_ident => #serialize_as,));
} }
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
quote!( quote!(
impl #impl_generics ToXml for #ident #ty_generics #where_clause { impl #impl_generics ToXml for #ident #ty_generics #where_clause {
fn serialize<W: ::core::fmt::Write + ?::core::marker::Sized>( fn serialize<W: ::core::fmt::Write + ?::core::marker::Sized>(
&self, &self,
serializer: &mut instant_xml::Serializer<W>, serializer: &mut instant_xml::Serializer<W>,
) -> Result<(), instant_xml::Error> { ) -> Result<(), instant_xml::Error> {
serializer.write_str(match self { #variants }) serializer.write_str(match self { #variants })
} }
const KIND: ::instant_xml::Kind = ::instant_xml::Kind::Scalar; const KIND: ::instant_xml::Kind = ::instant_xml::Kind::Scalar;
} }
) )
} }