Fix support for attributes with no default namespace fallback

This commit is contained in:
Dirkjan Ochtman 2022-09-07 22:14:21 +02:00
parent b30859929b
commit f64634155e
2 changed files with 26 additions and 1 deletions

View File

@ -122,7 +122,10 @@ fn process_named_field(
)
.into_compile_error(),
),
None => (quote!(#default_ns), quote!()),
None => (match default_ns {
Some(ns) => quote!(#ns),
None => quote!(""),
}, quote!()),
};
attributes.extend(quote!(

View File

@ -0,0 +1,22 @@
use similar_asserts::assert_eq;
use instant_xml::{from_str, to_string, FromXml, ToXml};
#[derive(Debug, Eq, PartialEq, FromXml, ToXml)]
struct Basic {
#[xml(attribute)]
flag: bool,
}
#[test]
fn basic() {
assert_eq!(
from_str::<Basic>("<Basic flag=\"true\"></Basic>"),
Ok(Basic { flag: true })
);
assert_eq!(
to_string(&Basic { flag: true }).unwrap(),
"<Basic flag=\"true\"></Basic>"
);
}