From 14746d9854bf8ec4b9afe972d46503e101180194 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Thu, 1 Sep 2022 11:17:41 +0200 Subject: [PATCH] Inline enum matching functions --- instant-xml-macros/src/de.rs | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/instant-xml-macros/src/de.rs b/instant-xml-macros/src/de.rs index 27b730f..3f7aba4 100644 --- a/instant-xml-macros/src/de.rs +++ b/instant-xml-macros/src/de.rs @@ -141,27 +141,11 @@ impl Deserializer { __Ignore, } - fn get_element(value: &str) -> __Elements { - #elements_consts - match value { - #elements_names - _ => __Elements::__Ignore - } - } - enum __Attributes { #attributes_enum __Ignore, } - fn get_attribute(value: &str) -> __Attributes { - #attributes_consts - match value { - #attributes_names - _ => __Attributes::__Ignore - } - } - struct StructVisitor<'xml #lifetime_xml> { marker: std::marker::PhantomData<#ident #generics>, lifetime: std::marker::PhantomData<&'xml ()>, @@ -176,7 +160,15 @@ impl Deserializer { ) -> Result { #declare_values while let Some(( key, _ )) = deserializer.peek_next_attribute() { - match get_attribute(&key) { + let attr = { + #attributes_consts + match *key { + #attributes_names + _ => __Attributes::__Ignore + } + }; + + match attr { #attr_type_match __Attributes::__Ignore => todo!(), } @@ -184,7 +176,15 @@ impl Deserializer { while let Some(item) = &deserializer.peek_next_tag()? { match item { XmlRecord::Open(item) => { - match get_element(&item.key.as_ref()) { + let element = { + #elements_consts + match item.key.as_ref() { + #elements_names + _ => __Elements::__Ignore + } + }; + + match element { #elem_type_match __Elements::__Ignore => panic!("No such element"), }