Skip to content

Commit 403d5e2

Browse files
authored
Merge pull request #92 from Koxiaet/clippy
Satisfy Clippy where ever possible
2 parents 12a88c5 + 14970d9 commit 403d5e2

File tree

9 files changed

+44
-33
lines changed

9 files changed

+44
-33
lines changed

src/body.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ impl Body {
126126
self.length
127127
}
128128

129+
/// Returns `true` if the body has a length of zero, and `false` otherwise.
130+
pub fn is_empty(&self) -> Option<bool> {
131+
self.length.map(|length| length == 0)
132+
}
133+
129134
/// Get the inner reader from the `Body`
130135
///
131136
/// # Examples

src/headers/header_name.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl<'a> std::convert::TryFrom<&'a str> for HeaderName {
7474
impl PartialEq<str> for HeaderName {
7575
fn eq(&self, other: &str) -> bool {
7676
match HeaderName::from_str(other) {
77-
Err(_) => return false,
77+
Err(_) => false,
7878
Ok(other) => self == &other,
7979
}
8080
}
@@ -83,7 +83,7 @@ impl PartialEq<str> for HeaderName {
8383
impl<'a> PartialEq<&'a str> for HeaderName {
8484
fn eq(&self, other: &&'a str) -> bool {
8585
match HeaderName::from_str(other) {
86-
Err(_) => return false,
86+
Err(_) => false,
8787
Ok(other) => self == &other,
8888
}
8989
}
@@ -92,7 +92,7 @@ impl<'a> PartialEq<&'a str> for HeaderName {
9292
impl PartialEq<String> for HeaderName {
9393
fn eq(&self, other: &String) -> bool {
9494
match HeaderName::from_str(&other) {
95-
Err(_) => return false,
95+
Err(_) => false,
9696
Ok(other) => self == &other,
9797
}
9898
}
@@ -101,7 +101,7 @@ impl PartialEq<String> for HeaderName {
101101
impl<'a> PartialEq<&String> for HeaderName {
102102
fn eq(&self, other: &&String) -> bool {
103103
match HeaderName::from_str(other) {
104-
Err(_) => return false,
104+
Err(_) => false,
105105
Ok(other) => self == &other,
106106
}
107107
}

src/headers/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,29 +95,29 @@ impl Headers {
9595
}
9696

9797
/// An iterator visiting all header pairs in arbitrary order.
98-
pub fn iter<'a>(&'a self) -> Iter<'a> {
98+
pub fn iter(&self) -> Iter<'_> {
9999
Iter {
100100
inner: self.headers.iter(),
101101
}
102102
}
103103

104104
/// An iterator visiting all header pairs in arbitrary order, with mutable references to the
105105
/// values.
106-
pub fn iter_mut<'a>(&'a mut self) -> IterMut<'a> {
106+
pub fn iter_mut(&mut self) -> IterMut<'_> {
107107
IterMut {
108108
inner: self.headers.iter_mut(),
109109
}
110110
}
111111

112112
/// An iterator visiting all header names in arbitrary order.
113-
pub fn names<'a>(&'a self) -> Names<'a> {
113+
pub fn names(&self) -> Names<'_> {
114114
Names {
115115
inner: self.headers.keys(),
116116
}
117117
}
118118

119119
/// An iterator visiting all header values in arbitrary order.
120-
pub fn values<'a>(&'a self) -> Values<'a> {
120+
pub fn values(&self) -> Values<'_> {
121121
Values::new(self.headers.values())
122122
}
123123
}

src/headers/values.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,10 @@ impl<'a> Iterator for Values<'a> {
2727
fn next(&mut self) -> Option<Self::Item> {
2828
loop {
2929
// Check if we have a vec in the current slot, and if not set one.
30-
if let None = self.slot {
31-
let next = self.inner.next();
32-
if next.is_none() {
33-
return None;
34-
}
30+
if self.slot.is_none() {
31+
let next = self.inner.next()?;
3532
self.cursor = 0;
36-
self.slot = next;
33+
self.slot = Some(next);
3734
}
3835

3936
// Get the next item

src/mime/parse.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub(crate) fn parse(s: &str) -> crate::Result<Mime> {
6868
// ```
6969
loop {
7070
// Stop parsing if there's no more bytes to consume.
71-
if s.fill_buf().unwrap().len() == 0 {
71+
if s.fill_buf().unwrap().is_empty() {
7272
break;
7373
}
7474

@@ -121,9 +121,8 @@ pub(crate) fn parse(s: &str) -> crate::Result<Mime> {
121121
param_value.make_ascii_lowercase();
122122

123123
// Insert attribute pair into hashmap.
124-
if let None = mime.parameters {
125-
mime.parameters = Some(HashMap::new());
126-
}
124+
mime.parameters.get_or_insert_with(HashMap::new);
125+
127126
mime.parameters
128127
.as_mut()
129128
.unwrap()

src/request.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,11 @@ impl Request {
318318
self.body.len()
319319
}
320320

321+
/// Returns `true` if the request has a set body stream length of zero, `false` otherwise.
322+
pub fn is_empty(&self) -> Option<bool> {
323+
self.body.is_empty()
324+
}
325+
321326
/// Get the HTTP version, if one has been set.
322327
///
323328
/// # Examples
@@ -400,7 +405,7 @@ impl Request {
400405
/// ```
401406
pub fn cookie(&self, name: &str) -> Result<Option<Cookie<'_>>, crate::Error> {
402407
let cookies = self.cookies()?;
403-
let cookie = cookies.into_iter().filter(|c| c.name() == name).next();
408+
let cookie = cookies.into_iter().find(|c| c.name() == name);
404409
Ok(cookie)
405410
}
406411

@@ -440,23 +445,23 @@ impl Request {
440445
}
441446

442447
/// An iterator visiting all header pairs in arbitrary order.
443-
pub fn iter<'a>(&'a self) -> headers::Iter<'a> {
448+
pub fn iter(&self) -> headers::Iter<'_> {
444449
self.headers.iter()
445450
}
446451

447452
/// An iterator visiting all header pairs in arbitrary order, with mutable references to the
448453
/// values.
449-
pub fn iter_mut<'a>(&'a mut self) -> headers::IterMut<'a> {
454+
pub fn iter_mut(&mut self) -> headers::IterMut<'_> {
450455
self.headers.iter_mut()
451456
}
452457

453458
/// An iterator visiting all header names in arbitrary order.
454-
pub fn header_names<'a>(&'a self) -> Names<'a> {
459+
pub fn header_names(&self) -> Names<'_> {
455460
self.headers.names()
456461
}
457462

458463
/// An iterator visiting all header values in arbitrary order.
459-
pub fn header_values<'a>(&'a self) -> Values<'a> {
464+
pub fn header_values(&self) -> Values<'_> {
460465
self.headers.values()
461466
}
462467

src/response.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,11 @@ impl Response {
278278
self.body.len()
279279
}
280280

281+
/// Returns `true` if the set length of the body stream is zero, `false` otherwise.
282+
pub fn is_empty(&self) -> Option<bool> {
283+
self.body.is_empty()
284+
}
285+
281286
/// Get the HTTP version, if one has been set.
282287
///
283288
/// # Examples
@@ -365,7 +370,7 @@ impl Response {
365370
/// ```
366371
pub fn cookie(&self, name: &str) -> Result<Option<Cookie<'_>>, crate::Error> {
367372
let cookies = self.cookies()?;
368-
let cookie = cookies.into_iter().filter(|c| c.name() == name).next();
373+
let cookie = cookies.into_iter().find(|c| c.name() == name);
369374
Ok(cookie)
370375
}
371376

@@ -405,23 +410,23 @@ impl Response {
405410
}
406411

407412
/// An iterator visiting all header pairs in arbitrary order.
408-
pub fn iter<'a>(&'a self) -> headers::Iter<'a> {
413+
pub fn iter(&self) -> headers::Iter<'_> {
409414
self.headers.iter()
410415
}
411416

412417
/// An iterator visiting all header pairs in arbitrary order, with mutable references to the
413418
/// values.
414-
pub fn iter_mut<'a>(&'a mut self) -> headers::IterMut<'a> {
419+
pub fn iter_mut(&mut self) -> headers::IterMut<'_> {
415420
self.headers.iter_mut()
416421
}
417422

418423
/// An iterator visiting all header names in arbitrary order.
419-
pub fn header_names<'a>(&'a self) -> Names<'a> {
424+
pub fn header_names(&self) -> Names<'_> {
420425
self.headers.names()
421426
}
422427

423428
/// An iterator visiting all header values in arbitrary order.
424-
pub fn header_values<'a>(&'a self) -> Values<'a> {
429+
pub fn header_values(&self) -> Values<'_> {
425430
self.headers.values()
426431
}
427432

src/trailers.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,23 +131,23 @@ impl Trailers {
131131
}
132132

133133
/// An iterator visiting all header pairs in arbitrary order.
134-
pub fn iter<'a>(&'a self) -> Iter<'a> {
134+
pub fn iter(&self) -> Iter<'_> {
135135
self.headers.iter()
136136
}
137137

138138
/// An iterator visiting all header pairs in arbitrary order, with mutable references to the
139139
/// values.
140-
pub fn iter_mut<'a>(&'a mut self) -> IterMut<'a> {
140+
pub fn iter_mut(&mut self) -> IterMut<'_> {
141141
self.headers.iter_mut()
142142
}
143143

144144
/// An iterator visiting all header names in arbitrary order.
145-
pub fn names<'a>(&'a self) -> Names<'a> {
145+
pub fn names(&self) -> Names<'_> {
146146
self.headers.names()
147147
}
148148

149149
/// An iterator visiting all header values in arbitrary order.
150-
pub fn values<'a>(&'a self) -> Values<'a> {
150+
pub fn values(&self) -> Values<'_> {
151151
self.headers.values()
152152
}
153153
}

src/type_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl TypeMap {
3131
/// If a value of this type already exists, it will be returned.
3232
pub fn insert<T: Send + Sync + 'static>(&mut self, val: T) -> Option<T> {
3333
self.map
34-
.get_or_insert_with(|| Default::default())
34+
.get_or_insert_with(Default::default)
3535
.insert(TypeId::of::<T>(), Box::new(val))
3636
.and_then(|boxed| (boxed as Box<dyn Any>).downcast().ok().map(|boxed| *boxed))
3737
}

0 commit comments

Comments
 (0)