refactor(headers): Use macros for headers where possible
This commit is contained in:
		| @@ -1,31 +1,11 @@ | ||||
| use std::fmt; | ||||
|  | ||||
| use header::{Header, HeaderFormat}; | ||||
| use header::parsing::from_one_raw_str; | ||||
|  | ||||
| /// The `Content-Length` header. | ||||
| /// | ||||
| /// Simply a wrapper around a `usize`. | ||||
| /// Simply a wrapper around a `u64`. | ||||
| #[derive(Copy, Clone, PartialEq, Debug)] | ||||
| pub struct ContentLength(pub u64); | ||||
|  | ||||
| deref!(ContentLength => u64); | ||||
|  | ||||
| impl Header for ContentLength { | ||||
|     fn header_name() -> &'static str { | ||||
|         "Content-Length" | ||||
|     } | ||||
|  | ||||
|     fn parse_header(raw: &[Vec<u8>]) -> Option<ContentLength> { | ||||
|         from_one_raw_str(raw).map(|u| ContentLength(u)) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl HeaderFormat for ContentLength { | ||||
|     fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||||
|        fmt::Display::fmt(&self.0, fmt) | ||||
|     } | ||||
| } | ||||
| impl_header!(ContentLength, | ||||
|              "Content-Length", | ||||
|              u64); | ||||
|  | ||||
| bench_header!(bench, ContentLength, { vec![b"42349984".to_vec()] }); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user