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,14 +1,24 @@
/// The `User-Agent` header field.
///
/// They can contain any value, so it just wraps a `String`.
#[derive(Clone, PartialEq, Debug)]
pub struct UserAgent(pub String);
impl_header!(UserAgent,
"User-Agent",
String);
bench_header!(bench, UserAgent, { vec![b"cargo bench".to_vec()] });
header! {
#[doc="`User-Agent` header, defined in"]
#[doc="[RFC7231](http://tools.ietf.org/html/rfc7231#section-5.5.3)"]
#[doc=""]
#[doc="The `User-Agent` header field contains information about the user"]
#[doc="agent originating the request, which is often used by servers to help"]
#[doc="identify the scope of reported interoperability problems, to work"]
#[doc="around or tailor responses to avoid particular user agent"]
#[doc="limitations, and for analytics regarding browser or operating system"]
#[doc="use. A user agent SHOULD send a User-Agent field in each request"]
#[doc="unless specifically configured not to do so."]
#[doc=""]
#[doc="# ABNF"]
#[doc="```plain"]
#[doc="User-Agent = product *( RWS ( product / comment ) )"]
#[doc="product = token [\"/\" product-version]"]
#[doc="product-version = token"]
#[doc="```"]
// TODO: Maybe write parsing according to the spec? (Split the String)
(UserAgent, "User-Agent") => [String]
}
#[test] fn test_format() {
use std::borrow::ToOwned;