xso-proc: provide FromXml::xml_name_matcher on derived impls
That way, derived implementations can also make use of the performance benefits.
This commit is contained in:
parent
126588b47d
commit
59af49c691
5 changed files with 166 additions and 3 deletions
|
|
@ -7,10 +7,10 @@
|
|||
//! Handling of structs
|
||||
|
||||
use proc_macro2::{Span, TokenStream};
|
||||
use quote::quote;
|
||||
use quote::{quote, ToTokens};
|
||||
use syn::{spanned::Spanned, *};
|
||||
|
||||
use crate::common::{AsXmlParts, FromXmlParts, ItemDef};
|
||||
use crate::common::{AsXmlParts, FromXmlParts, ItemDef, XmlNameMatcher};
|
||||
use crate::compound::Compound;
|
||||
use crate::error_message::ParentRef;
|
||||
use crate::meta::{reject_key, Flag, NameRef, NamespaceRef, QNameRef, XmlCompoundMeta};
|
||||
|
|
@ -168,6 +168,22 @@ impl StructInner {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn xml_name_matcher(&self) -> Result<XmlNameMatcher> {
|
||||
match self {
|
||||
Self::Transparent { ty, .. } => Ok(XmlNameMatcher::Custom(quote! {
|
||||
<#ty as ::xso::FromXml>::xml_name_matcher()
|
||||
})),
|
||||
Self::Compound {
|
||||
xml_namespace,
|
||||
xml_name,
|
||||
..
|
||||
} => Ok(XmlNameMatcher::Specific(
|
||||
xml_namespace.to_token_stream(),
|
||||
xml_name.to_token_stream(),
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn make_from_events_statemachine(
|
||||
&self,
|
||||
state_ty_ident: &Ident,
|
||||
|
|
@ -399,6 +415,7 @@ impl ItemDef for StructDef {
|
|||
#builder_ty_ident::new(#name_ident, #attrs_ident, ctx)
|
||||
},
|
||||
builder_ty_ident: builder_ty_ident.clone(),
|
||||
name_matcher: self.inner.xml_name_matcher()?,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue