Add flatten_attr attribute
I'd like to support a new flatten_attr attribute which allows flattening nested structs into the attributes of a single tag. I'm working with XML with lots of repeated nested attributes, and it becomes incredibly unwieldly if I can't do something like this.
#[test]
fn test_flatten_attr() {
use hard_xml::XmlRead;
#[derive(hard_xml::XmlRead, hard_xml::XmlWrite, PartialEq, Debug)]
#[xml(tag = "BaseAttrs")]
struct BaseAttrs {
#[xml(attr = "name")]
name: String,
#[xml(attr = "declaredType")]
declared_type: Option<String>,
}
#[derive(hard_xml::XmlRead, hard_xml::XmlWrite, PartialEq, Debug)]
#[xml(tag = "Float32")]
struct Float32 {
#[xml(flatten_attr)]
name: BaseAttrs,
#[xml(attr = "start")]
start: Option<f32>,
}
#[derive(hard_xml::XmlRead, hard_xml::XmlWrite, PartialEq, Debug)]
#[xml(tag = "Float64")]
struct Float64 {
#[xml(flatten_attr)]
name: BaseAttrs,
#[xml(attr = "start")]
start: Option<f64>,
}
let xml1 = r#"<Float32 name="var1" start="1.0"/>"#;
let float32: Float32 = Float32::from_str(xml1).unwrap();
let xml2 = r#"<Float64 name="var2" declared_type="some_type" start="2.0"/>"#;
let float64: Float64 = Float64::from_str(xml2).unwrap();
}