xml: XmlRoot add namespace checking

This commit is contained in:
Lennart
2024-12-23 11:37:09 +01:00
parent b5e0f68239
commit 825a65e348
3 changed files with 25 additions and 6 deletions

View File

@@ -36,6 +36,7 @@ pub struct StructAttrs {
pub container: ContainerAttrs,
pub root: Option<LitByteStr>,
pub ns: Option<LitByteStr>,
pub allow_invalid: Flag,
}

View File

@@ -51,9 +51,14 @@ impl NamedStruct {
let (impl_generics, type_generics, where_clause) = self.generics.split_for_impl();
let ident = &self.ident;
let root = self.attrs.root.as_ref().expect("No root attribute found");
let ns = match &self.attrs.ns {
Some(ns) => quote! { Some(#ns) },
None => quote! { None },
};
quote! {
impl #impl_generics ::rustical_xml::XmlRoot for #ident #type_generics #where_clause {
fn root_tag() -> &'static [u8] { #root }
fn root_ns() -> Option<&'static [u8]> { #ns }
}
}
}