Skip to content

Commit fd8f22f

Browse files
committed
cleaning up comments of ContentCoding and removing changes to ContentEncoding
1 parent 5eeb66f commit fd8f22f

File tree

2 files changed

+22
-32
lines changed

2 files changed

+22
-32
lines changed

src/common/content_coding.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use HeaderValue;
22

3+
// Derives an enum to represent content codings and some helpful impls
34
macro_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
$(

src/common/content_encoding.rs

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,11 @@ derive_header! {
3939
name: CONTENT_ENCODING
4040
}
4141

42-
macro_rules! derive_constructor {
43-
($(doc = $doc:expr; $coding:ident,)+) => {
44-
$(
45-
#[doc = $doc]
46-
#[inline]
47-
pub fn $coding() -> ContentEncoding {
48-
ContentEncoding(HeaderValue::from_static(stringify!($coding)).into())
49-
}
50-
)+
51-
};
52-
}
53-
5442
impl ContentEncoding {
55-
derive_constructor! {
56-
doc = "A constructor to easily create a `Content-Encoding`: gzip header";
57-
gzip,
58-
doc = "A constructor to easily create a `Content-Encoding`: compress header";
59-
compress,
60-
doc = "A constructor to easily create a `Content-Encoding`: deflate header";
61-
deflate,
62-
doc = "A constructor to easily create a `Content-Encoding`: identity header";
63-
identity,
64-
doc = "A constructor to easily create a `Content-Encoding`: br header";
65-
br,
43+
/// A constructor to easily create a `Content-Encoding: gzip` header.
44+
#[inline]
45+
pub fn gzip() -> ContentEncoding {
46+
ContentEncoding(HeaderValue::from_static("gzip").into())
6647
}
6748

6849
/// Check if this header contains a given "coding".

0 commit comments

Comments
 (0)