xso-proc: add debug mode for development purposes
This commit is contained in:
parent
32e8f2ec2e
commit
92e69cf59f
3 changed files with 27 additions and 0 deletions
|
@ -90,6 +90,10 @@ fn from_xml_impl(input: Item) -> Result<TokenStream> {
|
|||
}
|
||||
});
|
||||
|
||||
if def.debug() {
|
||||
println!("{}", result);
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
|
@ -151,6 +155,10 @@ fn into_xml_impl(input: Item) -> Result<TokenStream> {
|
|||
}
|
||||
});
|
||||
|
||||
if def.debug() {
|
||||
println!("{}", result);
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
|
|
|
@ -154,6 +154,9 @@ pub(crate) struct XmlCompoundMeta {
|
|||
|
||||
/// The value assigned to `name` inside `#[xml(..)]`, if any.
|
||||
pub(crate) name: Option<NameRef>,
|
||||
|
||||
/// The debug flag.
|
||||
pub(crate) debug: Flag,
|
||||
}
|
||||
|
||||
impl XmlCompoundMeta {
|
||||
|
@ -164,6 +167,7 @@ impl XmlCompoundMeta {
|
|||
fn parse_from_attribute(attr: &Attribute) -> Result<Self> {
|
||||
let mut namespace = None;
|
||||
let mut name = None;
|
||||
let mut debug = Flag::Absent;
|
||||
|
||||
attr.parse_nested_meta(|meta| {
|
||||
if meta.path.is_ident("name") {
|
||||
|
@ -178,6 +182,12 @@ impl XmlCompoundMeta {
|
|||
}
|
||||
namespace = Some(meta.value()?.parse()?);
|
||||
Ok(())
|
||||
} else if meta.path.is_ident("debug") {
|
||||
if debug.is_set() {
|
||||
return Err(Error::new_spanned(meta.path, "duplicate `debug` key"));
|
||||
}
|
||||
debug = (&meta.path).into();
|
||||
Ok(())
|
||||
} else {
|
||||
Err(Error::new_spanned(meta.path, "unsupported key"))
|
||||
}
|
||||
|
@ -187,6 +197,7 @@ impl XmlCompoundMeta {
|
|||
span: attr.span(),
|
||||
namespace,
|
||||
name,
|
||||
debug,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -56,6 +56,9 @@ pub(crate) struct StructDef {
|
|||
|
||||
/// Name of the iterator type.
|
||||
event_iter_ty_ident: Ident,
|
||||
|
||||
/// Flag whether debug mode is enabled.
|
||||
debug: bool,
|
||||
}
|
||||
|
||||
impl StructDef {
|
||||
|
@ -76,6 +79,7 @@ impl StructDef {
|
|||
target_ty_ident: ident.clone(),
|
||||
builder_ty_ident: quote::format_ident!("{}FromXmlBuilder", ident),
|
||||
event_iter_ty_ident: quote::format_ident!("{}IntoXmlIterator", ident),
|
||||
debug: meta.debug.is_set(),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -172,4 +176,8 @@ impl StructDef {
|
|||
event_iter_ty_ident: event_iter_ty_ident.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn debug(&self) -> bool {
|
||||
self.debug
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue