1use derive_more::From;
2use http::Uri;
3use rustical_xml::{XmlDeserialize, XmlSerialize};
4
5#[derive(XmlDeserialize, XmlSerialize, Debug, Clone, From, PartialEq, Eq)]
6pub struct HrefElement {
7 #[xml(ns = "crate::namespace::NS_DAV")]
8 pub href: Uri,
9}
10
11impl HrefElement {
12 #[must_use]
13 pub const fn new(href: Uri) -> Self {
14 Self { href }
15 }
16}
17
18#[cfg(test)]
19mod tests {
20 use super::HrefElement;
21 use http::Uri;
22 use rustical_xml::{XmlRootTag, XmlSerialize, XmlSerializeRoot};
23
24 #[derive(XmlSerialize, XmlRootTag)]
25 #[xml(root = "document")]
26 struct Document {
27 hello: HrefElement,
28 }
29
30 #[test]
31 fn test_serialize_resourcetype() {
32 let out = Document {
33 hello: HrefElement::new(Uri::from_static("/okaywow")),
34 }
35 .serialize_to_string()
36 .unwrap();
37 assert_eq!(
38 out,
39 r#"<?xml version="1.0" encoding="utf-8"?>
40<document>
41 <hello>
42 <href xmlns="DAV:">/okaywow</href>
43 </hello>
44</document>"#
45 );
46 }
47}