diff --git a/instant-xml-macros/src/ser.rs b/instant-xml-macros/src/ser.rs index b6ea3c9..12efcc2 100644 --- a/instant-xml-macros/src/ser.rs +++ b/instant-xml-macros/src/ser.rs @@ -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!( diff --git a/instant-xml/tests/attr-no-ns.rs b/instant-xml/tests/attr-no-ns.rs new file mode 100644 index 0000000..3dc73e0 --- /dev/null +++ b/instant-xml/tests/attr-no-ns.rs @@ -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::(""), + Ok(Basic { flag: true }) + ); + + assert_eq!( + to_string(&Basic { flag: true }).unwrap(), + "" + ); +}