use similar_asserts::assert_eq; use instant_xml::{from_str, FromXml}; #[derive(Debug, Eq, PartialEq, FromXml)] #[xml(ns("URI", bar = BAR))] struct NestedDe { #[xml(ns(BAR))] flag: bool, } #[derive(Debug, Eq, PartialEq, FromXml)] #[xml(ns("URI", bar = "BAZ", foo = "BAR"))] struct StructWithCustomFieldFromXml { #[xml(ns(BAR))] r#flag: bool, #[xml(attribute)] flag_attribute: bool, test: NestedDe, } const BAR: &str = "BAZ"; #[test] fn struct_with_custom_field_from_xml() { assert_eq!( from_str::("falsetrue").unwrap(), StructWithCustomFieldFromXml { flag: false, flag_attribute: true, test: NestedDe { flag: true } } ); // Different order assert_eq!( from_str::("truefalse").unwrap(), StructWithCustomFieldFromXml { flag: false, flag_attribute: true, test: NestedDe { flag: true } } ); // Different prefixes then in definition assert_eq!( from_str::("falsetrue").unwrap(), StructWithCustomFieldFromXml { flag: false, flag_attribute: true, test: NestedDe { flag: true } } ); assert_eq!( from_str::( "true" ) .unwrap(), NestedDe { flag: true } ); }