xso-proc: Add the default flag to the element meta
This allows the payload to be absent, and requires the field type to be Option<minidom::Element>.
This commit is contained in:
parent
c72cf3ddd1
commit
1823afbc71
6 changed files with 107 additions and 6 deletions
|
|
@ -755,6 +755,9 @@ pub(crate) enum XmlFieldMeta {
|
|||
/// This is useful for error messages.
|
||||
span: Span,
|
||||
|
||||
/// The `default` flag.
|
||||
default_: Flag,
|
||||
|
||||
/// The `n` flag.
|
||||
amount: Option<AmountConstraint>,
|
||||
},
|
||||
|
|
@ -1035,9 +1038,16 @@ impl XmlFieldMeta {
|
|||
/// Parse a `#[xml(element)]` meta.
|
||||
fn element_from_meta(meta: ParseNestedMeta<'_>) -> Result<Self> {
|
||||
let mut amount = None;
|
||||
let mut default_ = Flag::Absent;
|
||||
if meta.input.peek(syn::token::Paren) {
|
||||
meta.parse_nested_meta(|meta| {
|
||||
if meta.path.is_ident("n") {
|
||||
if meta.path.is_ident("default") {
|
||||
if default_.is_set() {
|
||||
return Err(Error::new_spanned(meta.path, "duplicate `default` key"));
|
||||
}
|
||||
default_ = (&meta.path).into();
|
||||
Ok(())
|
||||
} else if meta.path.is_ident("n") {
|
||||
if amount.is_some() {
|
||||
return Err(Error::new_spanned(meta.path, "duplicate `n` key"));
|
||||
}
|
||||
|
|
@ -1050,6 +1060,7 @@ impl XmlFieldMeta {
|
|||
}
|
||||
Ok(Self::Element {
|
||||
span: meta.path.span(),
|
||||
default_,
|
||||
amount,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue