1use crate::{utils::HeaderIteratorExt, DEPTH};
6
7#[derive(Clone, Debug, PartialEq)]
9pub enum Depth {
10 Zero,
11 One,
12 Infinity,
13}
14impl headers::Header for Depth {
15 fn name() -> &'static http::HeaderName {
16 &DEPTH
17 }
18 fn decode<'i, I>(values: &mut I) -> Result<Self, headers::Error>
19 where
20 Self: Sized,
21 I: Iterator<Item = &'i http::HeaderValue>,
22 {
23 match values.take_one().map(|v| v.as_bytes())? {
24 b"0" => Ok(Depth::Zero),
25 b"1" => Ok(Depth::One),
26 b"infinity" => Ok(Depth::Infinity),
27 _ => Err(headers::Error::invalid()),
28 }
29 }
30 fn encode<E: Extend<http::HeaderValue>>(&self, values: &mut E) {
31 values.extend(std::iter::once(match self {
32 Depth::Zero => headers::HeaderValue::from_static("0"),
33 Depth::One => headers::HeaderValue::from_static("1"),
34 Depth::Infinity => headers::HeaderValue::from_static("infinity"),
35 }))
36 }
37}
38
39#[cfg(test)]
40#[test]
41fn test() {
42 use crate::test::test_all;
43
44 test_all([
45 ("0", Depth::Zero),
46 ("1", Depth::One),
47 ("infinity", Depth::Infinity),
48 ]);
49}