rustical_dav/xml/
resourcetype.rs1use rustical_xml::XmlSerialize;
2
3#[derive(Debug, Clone, PartialEq, XmlSerialize)]
4pub struct Resourcetype(#[xml(flatten, ty = "untagged")] pub &'static [ResourcetypeInner]);
5
6#[derive(Debug, Clone, PartialEq, XmlSerialize)]
7pub struct ResourcetypeInner(
8 #[xml(ty = "namespace")] pub Option<quick_xml::name::Namespace<'static>>,
9 #[xml(ty = "tag_name")] pub &'static str,
10);
11
12#[cfg(test)]
13mod tests {
14 use rustical_xml::{XmlRootTag, XmlSerialize, XmlSerializeRoot};
15
16 use super::{Resourcetype, ResourcetypeInner};
17
18 #[derive(XmlSerialize, XmlRootTag)]
19 #[xml(root = b"document")]
20 struct Document {
21 resourcetype: Resourcetype,
22 }
23
24 #[test]
25 fn test_serialize_resourcetype() {
26 let mut buf = Vec::new();
27 let mut writer = quick_xml::Writer::new(&mut buf);
28 Document {
29 resourcetype: Resourcetype(&[
30 ResourcetypeInner(Some(crate::namespace::NS_DAV), "displayname"),
31 ResourcetypeInner(Some(crate::namespace::NS_CALENDARSERVER), "calendar-color"),
32 ]),
33 }
34 .serialize_root(&mut writer)
35 .unwrap();
36 let out = String::from_utf8(buf).unwrap();
37 assert_eq!(
38 out,
39 "<document><resourcetype><displayname xmlns=\"DAV:\"/><calendar-color xmlns=\"http://calendarserver.org/ns/\"/></resourcetype></document>"
40 )
41 }
42}