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

@@ -35,16 +35,21 @@ impl fmt::Display for Language {
}
}
/// The `Accept-Language` header
///
/// The `Accept-Language` header can be used by clients to indicate what
/// response languages they accept.
#[derive(Clone, PartialEq, Debug)]
pub struct AcceptLanguage(pub Vec<QualityItem<Language>>);
impl_list_header!(AcceptLanguage,
"Accept-Language",
Vec<QualityItem<Language>>);
header! {
#[doc="`Accept-Language` header, defined in"]
#[doc="[RFC7231](http://tools.ietf.org/html/rfc7231#section-5.3.5)"]
#[doc=""]
#[doc="The `Accept-Language` header field can be used by user agents to"]
#[doc="indicate the set of natural languages that are preferred in the"]
#[doc="response."]
#[doc=""]
#[doc="# ABNF"]
#[doc="```plain"]
#[doc="Accept-Language = 1#( language-range [ weight ] )"]
#[doc="language-range = <language-range, see [RFC4647], Section 2.1>"]
#[doc="```"]
(AcceptLanguage, "Accept-Language") => (QualityItem<Language>)+
}
#[cfg(test)]
mod tests {