Skip to main content

nextcloud_dav/method/
depth.rs

1/// Header carrying a WebDAV `Depth` value.
2pub const DEPTH_HEADER: &str = "Depth";
3
4/// How far a `PROPFIND` reaches below the addressed resource (RFC 4918
5/// ยง9.1).
6///
7/// The variants are the three tokens the specification defines; the server
8/// decides which of them it honours, and Nextcloud refuses `Infinity` for
9/// most trees.
10#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
11pub enum Depth {
12    /// The resource itself.
13    Zero,
14    /// The resource and its immediate children.
15    One,
16    /// The whole subtree.
17    Infinity,
18}
19
20impl Depth {
21    /// Wire representation for the [`DEPTH_HEADER`] value.
22    pub const fn as_header_value(self) -> &'static str {
23        match self {
24            Self::Zero => "0",
25            Self::One => "1",
26            Self::Infinity => "infinity",
27        }
28    }
29}
30
31#[cfg(test)]
32mod tests {
33    use super::{DEPTH_HEADER, Depth};
34
35    #[test]
36    fn header_values_use_the_specification_tokens() {
37        assert_eq!(Depth::Zero.as_header_value(), "0");
38        assert_eq!(Depth::One.as_header_value(), "1");
39        assert_eq!(Depth::Infinity.as_header_value(), "infinity");
40    }
41
42    #[test]
43    fn header_name_keeps_its_canonical_spelling() {
44        assert_eq!(DEPTH_HEADER, "Depth");
45    }
46}