mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 10:32:19 +00:00
xml: Fix attribute serialization
This commit is contained in:
@@ -196,10 +196,11 @@ impl NamedStruct {
|
|||||||
.filter(|field| field.attrs.xml_ty == FieldType::Attr)
|
.filter(|field| field.attrs.xml_ty == FieldType::Attr)
|
||||||
.map(|field| {
|
.map(|field| {
|
||||||
let field_name = field.xml_name();
|
let field_name = field.xml_name();
|
||||||
|
let field_ident = field.field_ident();
|
||||||
quote! {
|
quote! {
|
||||||
::quick_xml::events::attributes::Attribute {
|
::quick_xml::events::attributes::Attribute {
|
||||||
key: ::quick_xml::name::QName(#field_name),
|
key: ::quick_xml::name::QName(#field_name),
|
||||||
value: b"hello".into()
|
value: ::std::borrow::Cow::from(::rustical_xml::Value::serialize(&self.#field_ident).into_bytes())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -63,17 +63,19 @@ fn test_struct_value_tagged() {
|
|||||||
#[xml(root = b"document")]
|
#[xml(root = b"document")]
|
||||||
struct Document {
|
struct Document {
|
||||||
href: String,
|
href: String,
|
||||||
|
num: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
let mut writer = quick_xml::Writer::new(&mut buf);
|
let mut writer = quick_xml::Writer::new(&mut buf);
|
||||||
Document {
|
Document {
|
||||||
href: "okay".to_owned(),
|
href: "okay".to_owned(),
|
||||||
|
num: 123,
|
||||||
}
|
}
|
||||||
.serialize_root(&mut writer)
|
.serialize_root(&mut writer)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let out = String::from_utf8(buf).unwrap();
|
let out = String::from_utf8(buf).unwrap();
|
||||||
assert_eq!(out, "<document><href>okay</href></document>");
|
assert_eq!(out, "<document><href>okay</href><num>123</num></document>");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -88,10 +90,10 @@ fn test_struct_value_untagged() {
|
|||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
let mut writer = quick_xml::Writer::new(&mut buf);
|
let mut writer = quick_xml::Writer::new(&mut buf);
|
||||||
Document {
|
Document {
|
||||||
href: "okay".to_owned(),
|
href: "okays".to_owned(),
|
||||||
}
|
}
|
||||||
.serialize_root(&mut writer)
|
.serialize_root(&mut writer)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let out = String::from_utf8(buf).unwrap();
|
let out = String::from_utf8(buf).unwrap();
|
||||||
assert_eq!(out, "<document>okay</document>");
|
assert_eq!(out, "<document>okays</document>");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user