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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use std::fmt;
#[derive(Clone, PartialEq)]
pub struct Expect(());
impl Expect {
pub const CONTINUE: Expect = Expect(());
}
impl ::Header for Expect {
const NAME: &'static ::HeaderName = &::http::header::EXPECT;
fn decode(values: &mut ::Values) -> Option<Expect> {
if values.next()? == "100-continue" {
Some(Expect::CONTINUE)
} else {
None
}
}
fn encode(&self, values: &mut ::ToValues) {
values.append(::HeaderValue::from_static("100-continue"));
}
}
impl fmt::Debug for Expect {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple("Expect")
.field(&"100-continue")
.finish()
}
}
#[cfg(test)]
mod tests {
use super::Expect;
use super::super::test_decode;
#[test]
fn expect_continue() {
assert_eq!(
test_decode::<Expect>(&["100-continue"]),
Some(Expect::CONTINUE),
);
}
#[test]
fn expectation_failed() {
assert_eq!(
test_decode::<Expect>(&["sandwich"]),
None,
);
}
#[test]
fn too_many_values() {
assert_eq!(
test_decode::<Expect>(&["100-continue", "100-continue"]),
None,
);
}
}