xml: Add serialization

This commit is contained in:
Lennart
2024-12-23 10:46:33 +01:00
parent d9f7d1da2f
commit b5e0f68239
9 changed files with 141 additions and 33 deletions

View File

@@ -0,0 +1,29 @@
use rustical_xml::{XmlRoot, XmlSerialize};
use xml_derive::XmlDeserialize;
#[test]
fn test_struct_document() {
#[derive(Debug, XmlRoot, XmlSerialize, XmlDeserialize, PartialEq)]
#[xml(root = b"document")]
struct Document {
child: Child,
}
#[derive(Debug, XmlDeserialize, XmlSerialize, PartialEq, Default)]
struct Child {
#[xml(ty = "text")]
text: String,
}
let mut buf = Vec::new();
let mut writer = quick_xml::Writer::new(&mut buf);
Document {
child: Child {
text: "asd".to_owned(),
},
}
.serialize(Some(Document::root_tag()), &mut writer)
.unwrap();
let out = String::from_utf8(buf).unwrap();
dbg!(out);
}