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
#![deny(missing_docs)]
#![deny(missing_debug_implementations)]
#![cfg_attr(test, deny(warnings))]
#![doc(html_root_url = "https://docs.rs/headers-core/0.2.0")]
extern crate http;
pub use http::header::{self, HeaderName, HeaderValue};
use std::error;
use std::fmt::{self, Display, Formatter};
pub trait Header {
fn name() -> &'static HeaderName;
fn decode<'i, I>(values: &mut I) -> Result<Self, Error>
where
Self: Sized,
I: Iterator<Item = &'i HeaderValue>;
fn encode<E: Extend<HeaderValue>>(&self, values: &mut E);
}
#[derive(Debug)]
pub struct Error {
kind: Kind,
}
#[derive(Debug)]
enum Kind {
Invalid,
}
impl Error {
pub fn invalid() -> Error {
Error {
kind: Kind::Invalid,
}
}
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match &self.kind {
Kind::Invalid => f.write_str("invalid HTTP header"),
}
}
}
impl error::Error for Error {}