Skip to content

Commit 33002c4

Browse files
committed
refactor: format accept_encoding and content_coding modules
1 parent 11f96bd commit 33002c4

File tree

2 files changed

+32
-25
lines changed

2 files changed

+32
-25
lines changed

src/common/accept_encoding.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::convert::TryFrom;
22

3-
use {ContentCoding, HeaderValue};
43
use util::{QualityValue, TryFromValues};
4+
use {ContentCoding, HeaderValue};
55

66
/// `Accept-Encoding` header, defined in
77
/// [RFC7231](https://tools.ietf.org/html/rfc7231#section-5.3.4)
@@ -78,7 +78,11 @@ impl AcceptEncoding {
7878
/// assert_eq!(accept_enc.prefered_encoding(), Some(ContentCoding::GZIP));
7979
/// ```
8080
pub fn prefered_encoding(&self) -> Option<ContentCoding> {
81-
self.0.iter().peekable().peek().map(|s| ContentCoding::from_str(*s))
81+
self.0
82+
.iter()
83+
.peekable()
84+
.peek()
85+
.map(|s| ContentCoding::from_str(*s))
8286
}
8387

8488
/// Returns a quality sorted iterator of the `ContentCoding`
@@ -102,9 +106,9 @@ impl AcceptEncoding {
102106
}
103107

104108
/// Returns a quality sorted iterator of values
105-
///
109+
///
106110
/// # Example
107-
///
111+
///
108112
/// ```
109113
/// use headers::{AcceptEncoding, ContentCoding, HeaderValue};
110114
///

src/common/content_coding.rs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ use HeaderValue;
22

33
// Derives an enum to represent content codings and some helpful impls
44
macro_rules! define_content_coding {
5-
($($coding:ident; $str:expr,)+) => {
5+
($($coding:ident; $str:expr,)+) => {
66
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
7-
/// Values that are used with headers like [`Content-Encoding`](self::ContentEncoding) or
7+
/// Values that are used with headers like [`Content-Encoding`](self::ContentEncoding) or
88
/// [`Accept-Encoding`](self::AcceptEncoding)
9-
///
9+
///
1010
/// [RFC7231](https://www.iana.org/assignments/http-parameters/http-parameters.xhtml)
1111
pub enum ContentCoding {
1212
$(
@@ -17,12 +17,12 @@ macro_rules! define_content_coding {
1717

1818
impl ContentCoding {
1919
/// Returns a `&'static str` for a `ContentCoding`
20-
///
20+
///
2121
/// # Example
22-
///
22+
///
2323
/// ```
2424
/// use headers::ContentCoding;
25-
///
25+
///
2626
/// let coding = ContentCoding::BROTLI;
2727
/// assert_eq!(coding.to_static(), "br");
2828
/// ```
@@ -33,20 +33,20 @@ macro_rules! define_content_coding {
3333
}
3434
}
3535

36-
/// Given a `&str` returns a `ContentCoding`
37-
///
38-
/// Note this will never fail, in the case of `&str` being an invalid content coding,
39-
/// will return `ContentCoding::IDENTITY` because `'identity'` is generally always an
36+
/// Given a `&str` returns a `ContentCoding`
37+
///
38+
/// Note this will never fail, in the case of `&str` being an invalid content coding,
39+
/// will return `ContentCoding::IDENTITY` because `'identity'` is generally always an
4040
/// accepted coding.
41-
///
41+
///
4242
/// # Example
43-
///
43+
///
4444
/// ```
4545
/// use headers::ContentCoding;
46-
///
46+
///
4747
/// let invalid = ContentCoding::from_str("not a valid coding");
4848
/// assert_eq!(invalid, ContentCoding::IDENTITY);
49-
///
49+
///
5050
/// let valid = ContentCoding::from_str("gzip");
5151
/// assert_eq!(valid, ContentCoding::GZIP);
5252
/// ```
@@ -56,18 +56,18 @@ macro_rules! define_content_coding {
5656
}
5757

5858
/// Given a `&str` will try to return a `ContentCoding`
59-
///
59+
///
6060
/// Different from `ContentCoding::from_str(&str)`, if `&str` is an invalid content
6161
/// coding, it will return `Err(())`
62-
///
62+
///
6363
/// # Example
64-
///
64+
///
6565
/// ```
6666
/// use headers::ContentCoding;
67-
///
67+
///
6868
/// let invalid = ContentCoding::try_from_str("not a valid coding");
6969
/// assert!(invalid.is_err());
70-
///
70+
///
7171
/// let valid = ContentCoding::try_from_str("gzip");
7272
/// assert_eq!(valid.unwrap(), ContentCoding::GZIP);
7373
/// ```
@@ -128,12 +128,15 @@ mod tests {
128128
fn from_str() {
129129
assert_eq!(ContentCoding::from_str("br"), ContentCoding::BROTLI);
130130
assert_eq!(ContentCoding::from_str("GZIP"), ContentCoding::GZIP);
131-
assert_eq!(ContentCoding::from_str("blah blah"), ContentCoding::IDENTITY);
131+
assert_eq!(
132+
ContentCoding::from_str("blah blah"),
133+
ContentCoding::IDENTITY
134+
);
132135
}
133136

134137
#[test]
135138
fn try_from_str() {
136139
assert_eq!(ContentCoding::try_from_str("br"), Ok(ContentCoding::BROTLI));
137140
assert_eq!(ContentCoding::try_from_str("blah blah"), Err(()));
138141
}
139-
}
142+
}

0 commit comments

Comments
 (0)