refactor(headers): Introduce header!() macro, improve documentation

The new macro handles single value headers, list headers, and list
headers with at least one item.
It creates the item for the header and contains its documentation. The
new macro allows handling
more header cases in the future, it will also be possible to include
tests inside the macro.

BREAKING CHANGE: Removed impl_header!() and impl_list_header!() macros,
use new header!() macro.
This commit is contained in:
Pyfisch
2015-04-02 12:41:04 +02:00
parent eeba13b34d
commit 262c450f90
19 changed files with 367 additions and 225 deletions

View File

@@ -1,11 +1,21 @@
/// The `Content-Length` header.
///
/// Simply a wrapper around a `u64`.
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct ContentLength(pub u64);
impl_header!(ContentLength,
"Content-Length",
u64);
header! {
#[doc="`Content-Length` header, defined in"]
#[doc="[RFC7230](http://tools.ietf.org/html/rfc7230#section-3.3.2)"]
#[doc=""]
#[doc="When a message does not have a `Transfer-Encoding` header field, a"]
#[doc="Content-Length header field can provide the anticipated size, as a"]
#[doc="decimal number of octets, for a potential payload body. For messages"]
#[doc="that do include a payload body, the Content-Length field-value"]
#[doc="provides the framing information necessary for determining where the"]
#[doc="body (and message) ends. For messages that do not include a payload"]
#[doc="body, the Content-Length indicates the size of the selected"]
#[doc="representation."]
#[doc=""]
#[doc="# ABNF"]
#[doc="```plain"]
#[doc="Content-Length = 1*DIGIT"]
#[doc="```"]
(ContentLength, "Content-Length") => [u64]
}
bench_header!(bench, ContentLength, { vec![b"42349984".to_vec()] });