Inline enum matching functions

This commit is contained in:
Dirkjan Ochtman 2022-09-01 11:17:41 +02:00
parent e03a6ea087
commit 14746d9854
1 changed files with 18 additions and 18 deletions

View File

@ -141,27 +141,11 @@ impl Deserializer {
__Ignore, __Ignore,
} }
fn get_element(value: &str) -> __Elements {
#elements_consts
match value {
#elements_names
_ => __Elements::__Ignore
}
}
enum __Attributes { enum __Attributes {
#attributes_enum #attributes_enum
__Ignore, __Ignore,
} }
fn get_attribute(value: &str) -> __Attributes {
#attributes_consts
match value {
#attributes_names
_ => __Attributes::__Ignore
}
}
struct StructVisitor<'xml #lifetime_xml> { struct StructVisitor<'xml #lifetime_xml> {
marker: std::marker::PhantomData<#ident #generics>, marker: std::marker::PhantomData<#ident #generics>,
lifetime: std::marker::PhantomData<&'xml ()>, lifetime: std::marker::PhantomData<&'xml ()>,
@ -176,7 +160,15 @@ impl Deserializer {
) -> Result<Self::Value, ::instant_xml::Error> { ) -> Result<Self::Value, ::instant_xml::Error> {
#declare_values #declare_values
while let Some(( key, _ )) = deserializer.peek_next_attribute() { 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 #attr_type_match
__Attributes::__Ignore => todo!(), __Attributes::__Ignore => todo!(),
} }
@ -184,7 +176,15 @@ impl Deserializer {
while let Some(item) = &deserializer.peek_next_tag()? { while let Some(item) = &deserializer.peek_next_tag()? {
match item { match item {
XmlRecord::Open(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 #elem_type_match
__Elements::__Ignore => panic!("No such element"), __Elements::__Ignore => panic!("No such element"),
} }