11use HeaderValue ;
22
3+ // Derives an enum to represent content codings and some helpful impls
34macro_rules! define_content_coding {
45 ( $( $coding: ident; $str: expr, ) +) => {
56 #[ derive( Copy , Clone , Debug , Eq , PartialEq ) ]
6- /// Values that are used with headers like `Content-Encoding`
7- /// [RFC7231](https://www.iana.org/assignments/http-parameters/http-parameters.xhtml )
7+ /// Values that are used with headers like [ `Content-Encoding`](self::ContentEncoding) or
8+ /// [`Accept-Encoding`](self::AcceptEncoding )
89 ///
10+ /// [RFC7231](https://www.iana.org/assignments/http-parameters/http-parameters.xhtml)
911 pub enum ContentCoding {
1012 $(
1113 #[ doc = $str]
@@ -14,18 +16,27 @@ macro_rules! define_content_coding {
1416 }
1517
1618 impl ContentCoding {
17- /// Returns a static str for a ContentCoding
19+ /// Returns a `&'static str` for a `ContentCoding`
20+ ///
21+ /// # Example
22+ ///
23+ /// ```
24+ /// use headers::ContentCoding;
25+ ///
26+ /// let coding = ContentCoding::BROTLI;
27+ /// assert_eq!(coding.to_static(), "br");
28+ /// ```
1829 #[ inline]
1930 pub fn to_static( & self ) -> & ' static str {
2031 match * self {
2132 $( ContentCoding :: $coding => $str, ) +
2233 }
2334 }
2435
25- /// Given a &str returns a ContentCoding.
36+ /// Given a ` &str` returns a ` ContentCoding`
2637 ///
2738 /// Note this will never fail, in the case of `&str` being an invalid content coding,
28- /// will return `ContentCoding::IDENTITY` because identity is generally always an
39+ /// will return `ContentCoding::IDENTITY` because `' identity'` is generally always an
2940 /// accepted coding.
3041 ///
3142 /// # Example
@@ -39,14 +50,12 @@ macro_rules! define_content_coding {
3950 /// let valid = ContentCoding::from_str("gzip");
4051 /// assert_eq!(valid, ContentCoding::GZIP);
4152 /// ```
42- ///
4353 #[ inline]
4454 pub fn from_str( s: & str ) -> Self {
4555 ContentCoding :: try_from_str( s) . unwrap_or_else( |_| ContentCoding :: IDENTITY )
4656 }
4757
48- #[ inline]
49- /// Given a &str will try to return a ContentCoding
58+ /// Given a `&str` will try to return a `ContentCoding`
5059 ///
5160 /// Different from `ContentCoding::from_str(&str)`, if `&str` is an invalid content
5261 /// coding, it will return `Err(())`
@@ -62,7 +71,7 @@ macro_rules! define_content_coding {
6271 /// let valid = ContentCoding::try_from_str("gzip");
6372 /// assert_eq!(valid.unwrap(), ContentCoding::GZIP);
6473 /// ```
65- ///
74+ # [ inline ]
6675 pub fn try_from_str( s: & str ) -> Result <Self , ( ) > {
6776 match s {
6877 $(
0 commit comments