Fix clippy and minor issues (#32)

* Fix clippy and minor issues

* Remove allow clippy attribute

* Reduce RequestHeader flags visibility
This commit is contained in:
Juan Aguilar 2020-12-22 17:56:09 +01:00 committed by GitHub
parent f8c8d26402
commit 72cc69ab95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 28 additions and 33 deletions

View file

@ -187,14 +187,11 @@ impl MessageBody for Body {
impl PartialEq for Body {
fn eq(&self, other: &Body) -> bool {
match *self {
Body::None => matches!(*other, Body::None),
Body::Empty => matches!(*other, Body::Empty),
Body::Bytes(ref b) => match *other {
Body::Bytes(ref b2) => b == b2,
_ => false,
},
Body::Message(_) => false,
match (self, other) {
(Body::None, Body::None) => true,
(Body::Empty, Body::Empty) => true,
(Body::Bytes(ref b), Body::Bytes(ref b2)) => b == b2,
_ => false,
}
}
}

View file

@ -11,8 +11,7 @@ use futures::Stream;
use crate::codec::{AsyncRead, AsyncWrite, Framed};
use crate::http::error::HttpError;
use crate::http::header::{self, HeaderName, HeaderValue, AUTHORIZATION};
use crate::http::{ConnectionType, StatusCode, Uri};
use crate::http::{Payload, RequestHead};
use crate::http::{ConnectionType, Payload, RequestHead, StatusCode, Uri};
use crate::rt::time::timeout;
use crate::service::{IntoService, Service};
use crate::util::framed::{Dispatcher, DispatcherError};
@ -46,13 +45,16 @@ impl WebsocketsRequest {
Uri: TryFrom<U>,
<Uri as TryFrom<U>>::Error: Into<HttpError>,
{
let mut err = None;
let mut head = RequestHead::default();
match Uri::try_from(uri) {
Ok(uri) => head.uri = uri,
Err(e) => err = Some(e.into()),
}
let (head, err) = match Uri::try_from(uri) {
Ok(uri) => (
RequestHead {
uri,
..Default::default()
},
None,
),
Err(e) => (Default::default(), Some(e.into())),
};
WebsocketsRequest {
head,

View file

@ -125,7 +125,7 @@ impl<S, X, U> DispatcherConfig<S, X, U> {
}
}
/// Return state of connection keep-alive funcitonality
/// Return state of connection keep-alive functionality
pub(super) fn keep_alive_enabled(&self) -> bool {
self.ka_enabled
}

View file

@ -44,7 +44,7 @@ pub struct RequestHead {
pub headers: HeaderMap,
pub extensions: RefCell<Extensions>,
pub peer_addr: Option<net::SocketAddr>,
flags: Flags,
pub(super) flags: Flags,
}
impl Default for RequestHead {

View file

@ -334,9 +334,9 @@ impl ResponseBuilder {
Ok(value) => {
parts.headers.append(key, value);
}
Err(e) => self.err = log_error(e),
Err(e) => self.err = Some(log_error(e)),
},
Err(e) => self.err = log_error(e),
Err(e) => self.err = Some(log_error(e)),
};
}
self
@ -367,9 +367,9 @@ impl ResponseBuilder {
Ok(value) => {
parts.headers.insert(key, value);
}
Err(e) => self.err = log_error(e),
Err(e) => self.err = Some(log_error(e)),
},
Err(e) => self.err = log_error(e),
Err(e) => self.err = Some(log_error(e)),
};
}
self
@ -436,7 +436,7 @@ impl ResponseBuilder {
Ok(value) => {
parts.headers.insert(header::CONTENT_TYPE, value);
}
Err(e) => self.err = log_error(e),
Err(e) => self.err = Some(log_error(e)),
};
}
self
@ -741,11 +741,10 @@ impl fmt::Debug for ResponseBuilder {
}
}
#[allow(clippy::unnecessary_wraps)]
fn log_error<T: Into<HttpError>>(err: T) -> Option<HttpError> {
fn log_error<T: Into<HttpError>>(err: T) -> HttpError {
let e = err.into();
error!("Error in ResponseBuilder {}", e);
Some(e)
e
}
/// Helper converters

View file

@ -145,7 +145,7 @@ where
inner.waker.register(cx.waker());
let mut buffer = inner.buf.borrow_mut();
if let Poll::Pending = inner.service.poll_ready(cx)? {
if inner.service.poll_ready(cx)?.is_pending() {
if buffer.len() < self.size {
// buffer next request
inner.ready.set(false);

View file

@ -77,7 +77,7 @@ where
#[inline]
fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
if let Poll::Pending = self.service.poll_ready(cx)? {
if self.service.poll_ready(cx)?.is_pending() {
Poll::Pending
} else if !self.count.available(cx) {
log::trace!("InFlight limit exceeded");

View file

@ -197,10 +197,7 @@ impl AcceptEncoding {
};
let quality = match parts.len() {
1 => encoding.quality(),
_ => match f64::from_str(parts[1]) {
Ok(q) => q,
Err(_) => 0.0,
},
_ => f64::from_str(parts[1]).unwrap_or(0.0),
};
Some(AcceptEncoding { encoding, quality })
}