From f64634155e238b0ec776d412847d2bb3826b147d Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Wed, 7 Sep 2022 22:14:21 +0200 Subject: [PATCH] Fix support for attributes with no default namespace fallback --- instant-xml-macros/src/ser.rs | 5 ++++- instant-xml/tests/attr-no-ns.rs | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 instant-xml/tests/attr-no-ns.rs 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(), + "" + ); +}