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,19 +1,23 @@
use header::Encoding;
/// The `Content-Encoding` header.
///
/// This header describes the encoding of the message body. It can be
/// comma-separated, including multiple encodings.
///
/// ```notrust
/// Content-Encoding: gzip
/// ```
#[derive(Clone, PartialEq, Debug)]
pub struct ContentEncoding(pub Vec<Encoding>);
impl_list_header!(ContentEncoding,
"Content-Encoding",
Vec<Encoding>);
header! {
#[doc="`Content-Encoding` header, defined in"]
#[doc="[RFC7231](http://tools.ietf.org/html/rfc7231#section-3.1.2.2)"]
#[doc=""]
#[doc="The `Content-Encoding` header field indicates what content codings"]
#[doc="have been applied to the representation, beyond those inherent in the"]
#[doc="media type, and thus what decoding mechanisms have to be applied in"]
#[doc="order to obtain data in the media type referenced by the Content-Type"]
#[doc="header field. Content-Encoding is primarily used to allow a"]
#[doc="representation's data to be compressed without losing the identity of"]
#[doc="its underlying media type."]
#[doc=""]
#[doc="# ABNF"]
#[doc="```plain"]
#[doc="Content-Encoding = 1#content-coding"]
#[doc="```"]
(ContentEncoding, "ContentEncoding") => (Encoding)+
}
bench_header!(single, ContentEncoding, { vec![b"gzip".to_vec()] });
bench_header!(multiple, ContentEncoding, { vec![b"gzip, deflate".to_vec()] });