refactor(headers): Use macros for headers where possible

This commit is contained in:
Pyfisch
2015-02-16 19:26:40 +01:00
parent f554c09e12
commit de1be67262
11 changed files with 70 additions and 202 deletions

View File

@@ -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()] });