webdav_xml/elements/
propfind.rs1use bytestring::ByteString;
6
7use crate::{elements::Properties, Element, Error, Value, DAV_NAMESPACE, DAV_PREFIX};
8
9#[derive(Clone, Debug, PartialEq)]
11pub enum Propfind {
12 Propname,
13 Allprop { include: Option<Include> },
14 Prop(Properties),
15}
16
17impl Element for Propfind {
18 const NAMESPACE: &'static str = DAV_NAMESPACE;
19 const PREFIX: &'static str = DAV_PREFIX;
20 const LOCAL_NAME: &'static str = "propfind";
21}
22
23impl TryFrom<&Value> for Propfind {
24 type Error = Error;
25
26 fn try_from(value: &Value) -> Result<Self, Self::Error> {
27 let map = value.to_map()?;
28
29 match (
30 map.get::<Propname>(),
31 map.get::<Allprop>(),
32 map.get::<Properties>(),
33 ) {
34 (Some(_), None, None) => Ok(Propfind::Propname),
35 (None, Some(_), None) => Ok(Propfind::Allprop {
36 include: map.get().transpose()?,
37 }),
38 (None, None, Some(prop)) => Ok(Propfind::Prop(prop?)),
39 _ => Err(Error::ConflictingElements(
40 "`propname`, `allprop` and `include` must not be used at the same time",
41 )),
42 }
43 }
44}
45
46#[derive(Clone, Debug, PartialEq)]
48pub struct Propname;
49
50impl Element for Propname {
51 const NAMESPACE: &'static str = DAV_NAMESPACE;
52 const PREFIX: &'static str = DAV_PREFIX;
53 const LOCAL_NAME: &'static str = "propname";
54}
55
56impl TryFrom<&Value> for Propname {
57 type Error = Error;
58
59 fn try_from(_: &Value) -> Result<Self, Self::Error> {
60 Ok(Propname)
61 }
62}
63
64#[derive(Clone, Debug, PartialEq)]
66pub struct Allprop;
67
68impl Element for Allprop {
69 const NAMESPACE: &'static str = DAV_NAMESPACE;
70 const PREFIX: &'static str = DAV_PREFIX;
71 const LOCAL_NAME: &'static str = "allprop";
72}
73
74impl TryFrom<&Value> for Allprop {
75 type Error = Error;
76
77 fn try_from(_: &Value) -> Result<Self, Self::Error> {
78 Ok(Allprop)
79 }
80}
81
82#[derive(Clone, Debug, PartialEq)]
84pub struct Include(Vec<ByteString>);
85
86impl Element for Include {
87 const NAMESPACE: &'static str = DAV_NAMESPACE;
88 const PREFIX: &'static str = DAV_PREFIX;
89 const LOCAL_NAME: &'static str = "include";
90}
91
92impl TryFrom<&Value> for Include {
93 type Error = Error;
94
95 fn try_from(_: &Value) -> Result<Self, Self::Error> {
96 todo!()
97 }
98}