xso-proc: Allow #[xml(flag)] without params

The namespace defaults to the parent’s namespace, and the name to the
field name, so we can avoid needlessly duplicating that info.
This commit is contained in:
Emmanuel Gil Peyrot 2025-01-25 20:01:08 +01:00
commit fefc898fdf
4 changed files with 9 additions and 7 deletions

View file

@ -139,7 +139,7 @@ pub struct Resumed {
#[xml(namespace = ns::SM, name = "sm")] #[xml(namespace = ns::SM, name = "sm")]
pub struct StreamManagement { pub struct StreamManagement {
/// `<optional/>` flag. /// `<optional/>` flag.
#[xml(flag(name = "optional"))] #[xml(flag)]
pub optional: bool, pub optional: bool,
} }

View file

@ -25,7 +25,7 @@ pub struct Proceed;
#[xml(namespace = ns::TLS, name = "starttls")] #[xml(namespace = ns::TLS, name = "starttls")]
pub struct StartTls { pub struct StartTls {
/// Marker for mandatory StartTLS. /// Marker for mandatory StartTLS.
#[xml(flag(name = "required"))] #[xml(flag)]
pub required: bool, pub required: bool,
} }

View file

@ -1977,7 +1977,7 @@ fn extract_ignore_unknown_stuff_roundtrip() {
#[derive(FromXml, AsXml, PartialEq, Debug, Clone)] #[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
#[xml(namespace = NS1, name = "foo")] #[xml(namespace = NS1, name = "foo")]
struct Flag { struct Flag {
#[xml(flag(namespace = NS1, name = "flag"))] #[xml(flag)]
flag: bool, flag: bool,
} }

View file

@ -1055,10 +1055,12 @@ impl XmlFieldMeta {
/// Parse a `#[xml(flag)]` meta. /// Parse a `#[xml(flag)]` meta.
fn flag_from_meta(meta: ParseNestedMeta<'_>) -> Result<Self> { fn flag_from_meta(meta: ParseNestedMeta<'_>) -> Result<Self> {
let mut qname = QNameRef::default(); let mut qname = QNameRef::default();
meta.parse_nested_meta(|meta| match qname.parse_incremental_from_meta(meta)? { if meta.input.peek(syn::token::Paren) {
None => Ok(()), meta.parse_nested_meta(|meta| match qname.parse_incremental_from_meta(meta)? {
Some(meta) => Err(Error::new_spanned(meta.path, "unsupported key")), None => Ok(()),
})?; Some(meta) => Err(Error::new_spanned(meta.path, "unsupported key")),
})?;
}
Ok(Self::Flag { Ok(Self::Flag {
span: meta.path.span(), span: meta.path.span(),
qname, qname,