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:
		| @@ -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()] }); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user