mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 22:52:22 +00:00
xml: Work on struct serialization
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
use rustical_xml::{XmlRootTag, XmlSerialize};
|
||||
use rustical_xml::{XmlRootTag, XmlSerialize, XmlSerializeRoot};
|
||||
use xml_derive::XmlDeserialize;
|
||||
|
||||
#[test]
|
||||
fn test_struct_document() {
|
||||
#[derive(Debug, XmlRootTag, XmlSerialize, XmlDeserialize, PartialEq)]
|
||||
#[derive(Debug, XmlRootTag, XmlSerialize, PartialEq)]
|
||||
#[xml(root = b"document")]
|
||||
struct Document {
|
||||
child: Child,
|
||||
@@ -22,7 +22,38 @@ fn test_struct_document() {
|
||||
text: "asd".to_owned(),
|
||||
},
|
||||
}
|
||||
.serialize(Some(Document::root_tag()), &mut writer)
|
||||
.serialize_root(&mut writer)
|
||||
.unwrap();
|
||||
let out = String::from_utf8(buf).unwrap();
|
||||
dbg!(out);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_struct_untagged_attr() {
|
||||
#[derive(Debug, XmlRootTag, XmlSerialize, PartialEq)]
|
||||
#[xml(root = b"document")]
|
||||
struct Document {
|
||||
#[xml(ty = "attr")]
|
||||
name: String,
|
||||
#[xml(ty = "untagged")]
|
||||
child: Child,
|
||||
}
|
||||
|
||||
#[derive(Debug, XmlSerialize, PartialEq, Default)]
|
||||
struct Child {
|
||||
#[xml(ty = "attr")]
|
||||
text: String,
|
||||
}
|
||||
|
||||
let mut buf = Vec::new();
|
||||
let mut writer = quick_xml::Writer::new(&mut buf);
|
||||
Document {
|
||||
name: "okay".to_owned(),
|
||||
child: Child {
|
||||
text: "asd".to_owned(),
|
||||
},
|
||||
}
|
||||
.serialize_root(&mut writer)
|
||||
.unwrap();
|
||||
let out = String::from_utf8(buf).unwrap();
|
||||
dbg!(out);
|
||||
|
||||
Reference in New Issue
Block a user