style(lib): address clippy code style warnings
* Remove unnecessary return statements. * Combine identical `match` arms. * Collapse nested conditional. * Use `assert_ne` where applicable. * Lifetime elision.
This commit is contained in:
committed by
Sean McArthur
parent
5d19ef88b4
commit
1059eb349a
@@ -222,16 +222,16 @@ mod tests {
|
||||
|
||||
// left has more params
|
||||
cookie.append("foo", "bar");
|
||||
assert!(cookie != cookie2);
|
||||
assert_ne!(cookie, cookie2);
|
||||
|
||||
// same len, different params
|
||||
cookie2.append("bar", "foo");
|
||||
assert!(cookie != cookie2);
|
||||
assert_ne!(cookie, cookie2);
|
||||
|
||||
|
||||
// right has more params, and matching KV
|
||||
cookie2.append("foo", "bar");
|
||||
assert!(cookie != cookie2);
|
||||
assert_ne!(cookie, cookie2);
|
||||
|
||||
// same params, different order
|
||||
cookie.append("bar", "foo");
|
||||
|
||||
@@ -505,14 +505,13 @@ impl FromStr for Link {
|
||||
// https://tools.ietf.org/html/rfc5988#section-5.3
|
||||
if link_header.rel.is_none() {
|
||||
link_header.rel = match link_param_split.next() {
|
||||
None => return Err(::Error::Header),
|
||||
Some("") => return Err(::Error::Header),
|
||||
None | Some("") => return Err(::Error::Header),
|
||||
Some(s) => {
|
||||
s.trim_matches(|c: char| c == '"' || c.is_whitespace())
|
||||
.split(' ')
|
||||
.map(|t| t.trim().parse())
|
||||
.collect::<Result<Vec<RelationType>, _>>()
|
||||
.or_else(|_| return Err(::Error::Header))
|
||||
.or_else(|_| Err(::Error::Header))
|
||||
.ok()
|
||||
},
|
||||
};
|
||||
@@ -521,8 +520,7 @@ impl FromStr for Link {
|
||||
// Parse the `Context IRI`.
|
||||
// https://tools.ietf.org/html/rfc5988#section-5.2
|
||||
link_header.anchor = match link_param_split.next() {
|
||||
None => return Err(::Error::Header),
|
||||
Some("") => return Err(::Error::Header),
|
||||
None | Some("") => return Err(::Error::Header),
|
||||
Some(s) => match verify_and_trim(s.trim(), (b'"', b'"')) {
|
||||
Err(_) => return Err(::Error::Header),
|
||||
Ok(a) => Some(String::from(a)),
|
||||
@@ -533,14 +531,13 @@ impl FromStr for Link {
|
||||
// https://tools.ietf.org/html/rfc5988#section-5.3
|
||||
if link_header.rev.is_none() {
|
||||
link_header.rev = match link_param_split.next() {
|
||||
None => return Err(::Error::Header),
|
||||
Some("") => return Err(::Error::Header),
|
||||
None | Some("") => return Err(::Error::Header),
|
||||
Some(s) => {
|
||||
s.trim_matches(|c: char| c == '"' || c.is_whitespace())
|
||||
.split(' ')
|
||||
.map(|t| t.trim().parse())
|
||||
.collect::<Result<Vec<RelationType>, _>>()
|
||||
.or_else(|_| return Err(::Error::Header))
|
||||
.or_else(|_| Err(::Error::Header))
|
||||
.ok()
|
||||
},
|
||||
}
|
||||
@@ -552,8 +549,7 @@ impl FromStr for Link {
|
||||
|
||||
v.push(
|
||||
match link_param_split.next() {
|
||||
None => return Err(::Error::Header),
|
||||
Some("") => return Err(::Error::Header),
|
||||
None | Some("") => return Err(::Error::Header),
|
||||
Some(s) => match s.trim().parse() {
|
||||
Err(_) => return Err(::Error::Header),
|
||||
Ok(t) => t,
|
||||
@@ -567,14 +563,13 @@ impl FromStr for Link {
|
||||
// https://tools.ietf.org/html/rfc5988#section-5.4
|
||||
if link_header.media_desc.is_none() {
|
||||
link_header.media_desc = match link_param_split.next() {
|
||||
None => return Err(::Error::Header),
|
||||
Some("") => return Err(::Error::Header),
|
||||
None | Some("") => return Err(::Error::Header),
|
||||
Some(s) => {
|
||||
s.trim_matches(|c: char| c == '"' || c.is_whitespace())
|
||||
.split(',')
|
||||
.map(|t| t.trim().parse())
|
||||
.collect::<Result<Vec<MediaDesc>, _>>()
|
||||
.or_else(|_| return Err(::Error::Header))
|
||||
.or_else(|_| Err(::Error::Header))
|
||||
.ok()
|
||||
},
|
||||
};
|
||||
@@ -584,8 +579,7 @@ impl FromStr for Link {
|
||||
// https://tools.ietf.org/html/rfc5988#section-5.4
|
||||
if link_header.title.is_none() {
|
||||
link_header.title = match link_param_split.next() {
|
||||
None => return Err(::Error::Header),
|
||||
Some("") => return Err(::Error::Header),
|
||||
None | Some("") => return Err(::Error::Header),
|
||||
Some(s) => match verify_and_trim(s.trim(), (b'"', b'"')) {
|
||||
Err(_) => return Err(::Error::Header),
|
||||
Ok(t) => Some(String::from(t)),
|
||||
@@ -600,8 +594,7 @@ impl FromStr for Link {
|
||||
// https://tools.ietf.org/html/rfc5987#section-3.2.1
|
||||
if link_header.title_star.is_none() {
|
||||
link_header.title_star = match link_param_split.next() {
|
||||
None => return Err(::Error::Header),
|
||||
Some("") => return Err(::Error::Header),
|
||||
None | Some("") => return Err(::Error::Header),
|
||||
Some(s) => Some(String::from(s.trim())),
|
||||
};
|
||||
}
|
||||
@@ -610,8 +603,7 @@ impl FromStr for Link {
|
||||
// https://tools.ietf.org/html/rfc5988#section-5.4
|
||||
if link_header.media_type.is_none() {
|
||||
link_header.media_type = match link_param_split.next() {
|
||||
None => return Err(::Error::Header),
|
||||
Some("") => return Err(::Error::Header),
|
||||
None | Some("") => return Err(::Error::Header),
|
||||
Some(s) => match verify_and_trim(s.trim(), (b'"', b'"')) {
|
||||
Err(_) => return Err(::Error::Header),
|
||||
Ok(t) => match t.parse() {
|
||||
|
||||
@@ -104,8 +104,8 @@ impl FromStr for StrictTransportSecurity {
|
||||
.fold(Ok((None, None)), |res, dir| match (res, dir) {
|
||||
(Ok((None, sub)), Ok(Directive::MaxAge(age))) => Ok((Some(age), sub)),
|
||||
(Ok((age, None)), Ok(Directive::IncludeSubdomains)) => Ok((age, Some(()))),
|
||||
(Ok((Some(_), _)), Ok(Directive::MaxAge(_))) => Err(::Error::Header),
|
||||
(Ok((_, Some(_))), Ok(Directive::IncludeSubdomains)) => Err(::Error::Header),
|
||||
(Ok((Some(_), _)), Ok(Directive::MaxAge(_))) |
|
||||
(Ok((_, Some(_))), Ok(Directive::IncludeSubdomains)) |
|
||||
(_, Err(_)) => Err(::Error::Header),
|
||||
(res, _) => res
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user