rustical_dav/xml/
resourcetype.rs

1use 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 out = Document {
27            resourcetype: Resourcetype(&[
28                ResourcetypeInner(Some(crate::namespace::NS_DAV), "displayname"),
29                ResourcetypeInner(Some(crate::namespace::NS_CALENDARSERVER), "calendar-color"),
30            ]),
31        }
32        .serialize_to_string()
33        .unwrap();
34        assert_eq!(
35            out,
36            r#"<?xml version="1.0" encoding="utf-8"?>
37<document>
38    <resourcetype>
39        <displayname xmlns="DAV:"/>
40        <calendar-color xmlns="http://calendarserver.org/ns/"/>
41    </resourcetype>
42</document>"#
43        )
44    }
45}