1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use std::fmt;
use std::str::FromStr;
use std::convert::AsRef;
use std::ascii::AsciiExt;

pub mod header;
pub mod method;
pub mod response;
pub mod client;

pub use self::client::Client;
pub use self::method::Method;

pub enum Depth {
    Zero,
    One,
    Infinity,
}

impl Depth {
    fn name(&self) -> &str {
        match *self {
            Depth::Zero => "0",
            Depth::One => "1",
            Depth::Infinity => "Infinity",
        }
    }
}

impl fmt::Display for Depth {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str(self.name())
    }
}

impl FromStr for Depth {
    type Err = ();
    fn from_str(s: &str) -> Result<Depth, ()> {
        match s.to_ascii_uppercase().as_ref() {
            "0" => Ok(Depth::Zero),
            "1" => Ok(Depth::One),
            "INFINITY" => Ok(Depth::Infinity),
            _ => Err(()),
        }
    }
}