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 { impl PartialEq for Body {
fn eq(&self, other: &Body) -> bool { fn eq(&self, other: &Body) -> bool {
match *self { match (self, other) {
Body::None => matches!(*other, Body::None), (Body::None, Body::None) => true,
Body::Empty => matches!(*other, Body::Empty), (Body::Empty, Body::Empty) => true,
Body::Bytes(ref b) => match *other { (Body::Bytes(ref b), Body::Bytes(ref b2)) => b == b2,
Body::Bytes(ref b2) => b == b2, _ => false,
_ => false,
},
Body::Message(_) => false,
} }
} }
} }

View file

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

View file

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

View file

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

View file

@ -145,7 +145,7 @@ where
inner.waker.register(cx.waker()); inner.waker.register(cx.waker());
let mut buffer = inner.buf.borrow_mut(); 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 { if buffer.len() < self.size {
// buffer next request // buffer next request
inner.ready.set(false); inner.ready.set(false);

View file

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

View file

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