Skip to content

Commit 1e2bc4a

Browse files
committed
clippy
1 parent 3cdfdad commit 1e2bc4a

File tree

15 files changed

+66
-94
lines changed

15 files changed

+66
-94
lines changed

ntex-router/src/quoter.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ pub(super) fn requote(val: &[u8]) -> Option<String> {
5050

5151
#[inline]
5252
fn from_hex(v: u8) -> Option<u8> {
53-
if v >= b'0' && v <= b'9' {
53+
if (b'0'..=b'9').contains(&v) {
5454
Some(v - 0x30) // ord('0') == 0x30
55-
} else if v >= b'A' && v <= b'F' {
55+
} else if (b'A'..=b'F').contains(&v) {
5656
Some(v - 0x41 + 10) // ord('A') == 0x41
57-
} else if v >= b'a' && v <= b'f' {
57+
} else if (b'a'..=b'f').contains(&v) {
5858
Some(v - 0x61 + 10) // ord('a') == 0x61
5959
} else {
6060
None

ntex-router/src/resource.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,16 @@ enum PathElement {
3232

3333
impl PathElement {
3434
fn is_str(&self) -> bool {
35-
match self {
36-
PathElement::Str(_) => true,
37-
_ => false,
38-
}
35+
matches!(self, PathElement::Str(_))
3936
}
37+
4038
fn into_str(self) -> String {
4139
match self {
4240
PathElement::Str(s) => s,
4341
_ => panic!(),
4442
}
4543
}
44+
4645
fn as_str(&self) -> &str {
4746
match self {
4847
PathElement::Str(s) => s.as_str(),
@@ -380,10 +379,8 @@ impl ResourceDef {
380379
}
381380
if !pattern.is_empty() {
382381
// handle tail expression for static segment
383-
if pattern.ends_with('*') {
384-
let pattern =
385-
Regex::new(&format!("^{}(.+)", &pattern[..pattern.len() - 1]))
386-
.unwrap();
382+
if let Some(stripped) = pattern.strip_suffix('*') {
383+
let pattern = Regex::new(&format!("^{}(.+)", stripped)).unwrap();
387384
pelems.push(Segment::Dynamic {
388385
pattern,
389386
names: Vec::new(),

ntex-router/src/tree.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ impl Tree {
244244
}
245245
}
246246

247-
let path = if path.starts_with('/') {
248-
&path[1..]
247+
let path = if let Some(path) = path.strip_prefix('/') {
248+
path
249249
} else {
250250
base_skip -= 1;
251251
path
@@ -282,8 +282,8 @@ impl Tree {
282282
return None;
283283
}
284284

285-
let path = if path.starts_with('/') {
286-
&path[1..]
285+
let path = if let Some(path) = path.strip_prefix('/') {
286+
path
287287
} else {
288288
base_skip -= 1;
289289
path
@@ -356,11 +356,8 @@ impl Tree {
356356
path.len()
357357
};
358358
let segment = T::unquote(&path[..idx]);
359-
let quoted = if let Cow::Owned(_) = segment {
360-
true
361-
} else {
362-
false
363-
};
359+
let quoted = matches!(segment, Cow::Owned(_));
360+
364361
// check segment match
365362
let is_match = match key[0] {
366363
Segment::Static(ref pattern) => {

ntex-rt/src/arbiter.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,7 @@ impl Arbiter {
114114
.unbounded_send(SystemCommand::RegisterArbiter(id, arb));
115115

116116
// run loop
117-
let _ = match rt.block_on(stop_rx) {
118-
Ok(code) => code,
119-
Err(_) => 1,
120-
};
117+
let _ = rt.block_on(stop_rx);
121118

122119
// unregister arbiter
123120
let _ = System::current()

ntex-rt/src/builder.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl AsyncSystemRunner {
130130

131131
// run loop
132132
lazy(|_| async {
133-
let res = match stop.await {
133+
match stop.await {
134134
Ok(code) => {
135135
if code != 0 {
136136
Err(io::Error::new(
@@ -142,8 +142,7 @@ impl AsyncSystemRunner {
142142
}
143143
}
144144
Err(e) => Err(io::Error::new(io::ErrorKind::Other, e)),
145-
};
146-
return res;
145+
}
147146
})
148147
.flatten()
149148
}

ntex/src/http/body.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ pub enum BodySize {
1818

1919
impl BodySize {
2020
pub fn is_eof(&self) -> bool {
21-
match self {
22-
BodySize::None | BodySize::Empty | BodySize::Sized(0) => true,
23-
_ => false,
24-
}
21+
matches!(self, BodySize::None | BodySize::Empty | BodySize::Sized(0))
2522
}
2623
}
2724

@@ -191,14 +188,8 @@ impl MessageBody for Body {
191188
impl PartialEq for Body {
192189
fn eq(&self, other: &Body) -> bool {
193190
match *self {
194-
Body::None => match *other {
195-
Body::None => true,
196-
_ => false,
197-
},
198-
Body::Empty => match *other {
199-
Body::Empty => true,
200-
_ => false,
201-
},
191+
Body::None => matches!(*other, Body::None),
192+
Body::Empty => matches!(*other, Body::Empty),
202193
Body::Bytes(ref b) => match *other {
203194
Body::Bytes(ref b2) => b == b2,
204195
_ => false,

ntex/src/http/client/h2proto.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ where
3131
trace!("Sending client request: {:?} {:?}", head, body.size());
3232
let head_req = head.as_ref().method == Method::HEAD;
3333
let length = body.size();
34-
let eof = match length {
35-
BodySize::None | BodySize::Empty | BodySize::Sized(0) => true,
36-
_ => false,
37-
};
34+
let eof = matches!(
35+
length,
36+
BodySize::None | BodySize::Empty | BodySize::Sized(0)
37+
);
3838

3939
let mut req = Request::new(());
4040
*req.uri_mut() = head.as_ref().uri.clone();

ntex/src/http/client/pool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ where
140140
// use existing connection
141141
Acquire::Acquired(io, created) => {
142142
trace!("Use existing connection for {:?}", req.uri);
143-
return Ok(IoConnection::new(
143+
Ok(IoConnection::new(
144144
io,
145145
created,
146146
Some(Acquired(key, Some(inner))),
147-
));
147+
))
148148
}
149149
// open new tcp connection
150150
Acquire::Available => {

ntex/src/http/client/sender.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl RequestHeadType {
154154
SendClientRequest::new(
155155
config.connector.send_request(self, body.into(), addr),
156156
response_decompress,
157-
timeout.or_else(|| config.timeout),
157+
timeout.or(config.timeout),
158158
)
159159
}
160160

ntex/src/http/client/ws.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use futures::Stream;
1111
use crate::codec::{AsyncRead, AsyncWrite, Framed};
1212
use crate::http::error::HttpError;
1313
use crate::http::header::{self, HeaderName, HeaderValue, AUTHORIZATION};
14-
use crate::http::{ConnectionType, Method, StatusCode, Uri, Version};
14+
use crate::http::{ConnectionType, StatusCode, Uri};
1515
use crate::http::{Payload, RequestHead};
1616
use crate::rt::time::timeout;
1717
use crate::service::{IntoService, Service};
@@ -48,8 +48,6 @@ impl WebsocketsRequest {
4848
{
4949
let mut err = None;
5050
let mut head = RequestHead::default();
51-
head.method = Method::GET;
52-
head.version = Version::HTTP_11;
5351

5452
match Uri::try_from(uri) {
5553
Ok(uri) => head.uri = uri,

0 commit comments

Comments
 (0)