1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-12-20 23:26:44 +00:00

improve code readability

This commit is contained in:
Rob Ede 2021-01-04 00:49:02 +00:00
parent e1683313ec
commit 21f6c9d7a5
No known key found for this signature in database
GPG key ID: C2A3B36E841A91E6
34 changed files with 238 additions and 230 deletions

View file

@ -176,7 +176,7 @@ mod _original {
buf[5] = b'0';
buf[7] = b'9';
}
_ => (),
_ => {},
}
let mut curr: isize = 12;

View file

@ -371,7 +371,7 @@ impl MessageBody for String {
pub struct BodyStream<S: Unpin, E> {
#[pin]
stream: S,
_t: PhantomData<E>,
_phantom: PhantomData<E>,
}
impl<S, E> BodyStream<S, E>
@ -382,7 +382,7 @@ where
pub fn new(stream: S) -> Self {
BodyStream {
stream,
_t: PhantomData,
_phantom: PhantomData,
}
}
}

View file

@ -28,7 +28,7 @@ pub struct HttpServiceBuilder<T, S, X = ExpectHandler, U = UpgradeHandler> {
expect: X,
upgrade: Option<U>,
on_connect_ext: Option<Rc<ConnectCallback<T>>>,
_t: PhantomData<S>,
_phantom: PhantomData<S>,
}
impl<T, S> HttpServiceBuilder<T, S, ExpectHandler, UpgradeHandler>
@ -49,7 +49,7 @@ where
expect: ExpectHandler,
upgrade: None,
on_connect_ext: None,
_t: PhantomData,
_phantom: PhantomData,
}
}
}
@ -138,7 +138,7 @@ where
expect: expect.into_factory(),
upgrade: self.upgrade,
on_connect_ext: self.on_connect_ext,
_t: PhantomData,
_phantom: PhantomData,
}
}
@ -163,7 +163,7 @@ where
expect: self.expect,
upgrade: Some(upgrade.into_factory()),
on_connect_ext: self.on_connect_ext,
_t: PhantomData,
_phantom: PhantomData,
}
}

View file

@ -52,7 +52,7 @@ pub struct Connector<T, U> {
config: ConnectorConfig,
#[allow(dead_code)]
ssl: SslConnector,
_t: PhantomData<U>,
_phantom: PhantomData<U>,
}
trait Io: AsyncRead + AsyncWrite + Unpin {}
@ -72,7 +72,7 @@ impl Connector<(), ()> {
ssl: Self::build_ssl(vec![b"h2".to_vec(), b"http/1.1".to_vec()]),
connector: default_connector(),
config: ConnectorConfig::default(),
_t: PhantomData,
_phantom: PhantomData,
}
}
@ -126,7 +126,7 @@ impl<T, U> Connector<T, U> {
connector,
config: self.config,
ssl: self.ssl,
_t: PhantomData,
_phantom: PhantomData,
}
}
}
@ -468,11 +468,11 @@ mod connect_impl {
match req.uri.scheme_str() {
Some("https") | Some("wss") => Either::Right(InnerConnectorResponseB {
fut: self.ssl_pool.call(req),
_t: PhantomData,
_phantom: PhantomData,
}),
_ => Either::Left(InnerConnectorResponseA {
fut: self.tcp_pool.call(req),
_t: PhantomData,
_phantom: PhantomData,
}),
}
}
@ -486,7 +486,7 @@ mod connect_impl {
{
#[pin]
fut: <ConnectionPool<T, Io1> as Service<Connect>>::Future,
_t: PhantomData<Io2>,
_phantom: PhantomData<Io2>,
}
impl<T, Io1, Io2> Future for InnerConnectorResponseA<T, Io1, Io2>
@ -513,7 +513,7 @@ mod connect_impl {
{
#[pin]
fut: <ConnectionPool<T, Io2> as Service<Connect>>::Future,
_t: PhantomData<Io1>,
_phantom: PhantomData<Io1>,
}
impl<T, Io1, Io2> Future for InnerConnectorResponseB<T, Io1, Io2>

View file

@ -72,7 +72,7 @@ where
// send request body
match body.size() {
BodySize::None | BodySize::Empty | BodySize::Sized(0) => (),
BodySize::None | BodySize::Empty | BodySize::Sized(0) => {},
_ => send_body(body, Pin::new(&mut framed_inner)).await?,
};

View file

@ -89,7 +89,7 @@ where
CONNECTION | TRANSFER_ENCODING => continue, // http2 specific
CONTENT_LENGTH if skip_len => continue,
// DATE => has_date = true,
_ => (),
_ => {},
}
req.headers_mut().append(key, value.clone());
}

View file

@ -334,7 +334,7 @@ where
let mut read_buf = ReadBuf::new(&mut buf);
if let ConnectionType::H1(ref mut s) = io {
match Pin::new(s).poll_read(cx, &mut read_buf) {
Poll::Pending => (),
Poll::Pending => {},
Poll::Ready(Ok(())) if !read_buf.filled().is_empty() => {
if let Some(timeout) = self.config.disconnect_timeout {
if let ConnectionType::H1(io) = io {

View file

@ -137,7 +137,7 @@ pub(crate) trait MessageType: Sized {
expect = true;
}
}
_ => (),
_ => {},
}
headers.append(name, value);
@ -685,7 +685,7 @@ mod tests {
match MessageDecoder::<Request>::default().decode($e) {
Err(err) => match err {
ParseError::Io(_) => unreachable!("Parse error expected"),
_ => (),
_ => {},
},
_ => unreachable!("Error expected"),
}

View file

@ -736,7 +736,7 @@ where
let _ = this.ka_timer.as_mut().as_pin_mut().unwrap().poll(cx);
}
}
Poll::Pending => (),
Poll::Pending => {},
}
Ok(())

View file

@ -21,7 +21,7 @@ const AVERAGE_HEADER_SIZE: usize = 30;
pub(crate) struct MessageEncoder<T: MessageType> {
pub length: BodySize,
pub te: TransferEncoding,
_t: PhantomData<T>,
_phantom: PhantomData<T>,
}
impl<T: MessageType> Default for MessageEncoder<T> {
@ -29,7 +29,7 @@ impl<T: MessageType> Default for MessageEncoder<T> {
MessageEncoder {
length: BodySize::None,
te: TransferEncoding::empty(),
_t: PhantomData,
_phantom: PhantomData,
}
}
}
@ -118,7 +118,7 @@ pub(crate) trait MessageType: Sized {
dst.put_slice(b"connection: close\r\n")
}
}
_ => (),
_ => {},
}
// merging headers from head and extra headers. HeaderMap::new() does not allocate.
@ -148,7 +148,7 @@ pub(crate) trait MessageType: Sized {
CONNECTION => continue,
TRANSFER_ENCODING | CONTENT_LENGTH if skip_len => continue,
DATE => has_date = true,
_ => (),
_ => {},
}
let k = key.as_str().as_bytes();

View file

@ -30,7 +30,7 @@ pub struct H1Service<T, S, B, X = ExpectHandler, U = UpgradeHandler> {
expect: X,
upgrade: Option<U>,
on_connect_ext: Option<Rc<ConnectCallback<T>>>,
_t: PhantomData<B>,
_phantom: PhantomData<B>,
}
impl<T, S, B> H1Service<T, S, B>
@ -52,7 +52,7 @@ where
expect: ExpectHandler,
upgrade: None,
on_connect_ext: None,
_t: PhantomData,
_phantom: PhantomData,
}
}
}
@ -211,7 +211,7 @@ where
srv: self.srv,
upgrade: self.upgrade,
on_connect_ext: self.on_connect_ext,
_t: PhantomData,
_phantom: PhantomData,
}
}
@ -227,7 +227,7 @@ where
srv: self.srv,
expect: self.expect,
on_connect_ext: self.on_connect_ext,
_t: PhantomData,
_phantom: PhantomData,
}
}
@ -270,7 +270,7 @@ where
upgrade: None,
on_connect_ext: self.on_connect_ext.clone(),
cfg: Some(self.cfg.clone()),
_t: PhantomData,
_phantom: PhantomData,
}
}
}
@ -299,7 +299,7 @@ where
upgrade: Option<U::Service>,
on_connect_ext: Option<Rc<ConnectCallback<T>>>,
cfg: Option<ServiceConfig>,
_t: PhantomData<(T, B)>,
_phantom: PhantomData<(T, B)>,
}
impl<T, S, B, X, U> Future for H1ServiceResponse<T, S, B, X, U>
@ -371,7 +371,7 @@ where
upgrade: Option<CloneableService<U>>,
on_connect_ext: Option<Rc<ConnectCallback<T>>>,
cfg: ServiceConfig,
_t: PhantomData<B>,
_phantom: PhantomData<B>,
}
impl<T, S, B, X, U> H1ServiceHandler<T, S, B, X, U>
@ -398,7 +398,7 @@ where
upgrade: upgrade.map(CloneableService::new),
cfg,
on_connect_ext,
_t: PhantomData,
_phantom: PhantomData,
}
}
}

View file

@ -1,14 +1,15 @@
use std::convert::TryFrom;
use std::future::Future;
use std::marker::PhantomData;
use std::net;
use std::pin::Pin;
use std::task::{Context, Poll};
use std::{cmp, convert::TryFrom};
use actix_codec::{AsyncRead, AsyncWrite};
use actix_rt::time::{Instant, Sleep};
use actix_service::Service;
use bytes::{Bytes, BytesMut};
use futures_core::ready;
use h2::server::{Connection, SendResponse};
use h2::SendStream;
use http::header::{HeaderValue, CONNECTION, CONTENT_LENGTH, DATE, TRANSFER_ENCODING};
@ -27,7 +28,7 @@ use crate::Extensions;
const CHUNK_SIZE: usize = 16_384;
/// Dispatcher for HTTP/2 protocol
/// Dispatcher for HTTP/2 protocol.
#[pin_project::pin_project]
pub struct Dispatcher<T, S, B>
where
@ -42,7 +43,7 @@ where
peer_addr: Option<net::SocketAddr>,
ka_expire: Instant,
ka_timer: Option<Sleep>,
_t: PhantomData<B>,
_phantom: PhantomData<B>,
}
impl<T, S, B> Dispatcher<T, S, B>
@ -50,7 +51,6 @@ where
T: AsyncRead + AsyncWrite + Unpin,
S: Service<Request>,
S::Error: Into<Error>,
// S::Future: 'static,
S::Response: Into<Response<B>>,
B: MessageBody,
{
@ -86,7 +86,7 @@ where
on_connect_data,
ka_expire,
ka_timer,
_t: PhantomData,
_phantom: PhantomData,
}
}
}
@ -107,10 +107,12 @@ where
let this = self.get_mut();
loop {
match Pin::new(&mut this.connection).poll_accept(cx) {
Poll::Ready(None) => return Poll::Ready(Ok(())),
Poll::Ready(Some(Err(err))) => return Poll::Ready(Err(err.into())),
Poll::Ready(Some(Ok((req, res)))) => {
match ready!(Pin::new(&mut this.connection).poll_accept(cx)) {
None => return Poll::Ready(Ok(())),
Some(Err(err)) => return Poll::Ready(Err(err.into())),
Some(Ok((req, res))) => {
// update keep-alive expire
if this.ka_timer.is_some() {
if let Some(expire) = this.config.keep_alive_expire() {
@ -119,11 +121,9 @@ where
}
let (parts, body) = req.into_parts();
let mut req = Request::with_payload(Payload::<
crate::payload::PayloadStream,
>::H2(
crate::h2::Payload::new(body)
));
let pl = crate::h2::Payload::new(body);
let pl = Payload::<crate::payload::PayloadStream>::H2(pl);
let mut req = Request::with_payload(pl);
let head = &mut req.head_mut();
head.uri = parts.uri;
@ -135,22 +135,18 @@ where
// merge on_connect_ext data into request extensions
req.extensions_mut().drain_from(&mut this.on_connect_data);
actix_rt::spawn(ServiceResponse::<
S::Future,
S::Response,
S::Error,
B,
> {
let svc = ServiceResponse::<S::Future, S::Response, S::Error, B> {
state: ServiceResponseState::ServiceCall(
this.service.call(req),
Some(res),
),
config: this.config.clone(),
buffer: None,
_t: PhantomData,
});
_phantom: PhantomData,
};
actix_rt::spawn(svc);
}
Poll::Pending => return Poll::Pending,
}
}
}
@ -162,7 +158,7 @@ struct ServiceResponse<F, I, E, B> {
state: ServiceResponseState<F, B>,
config: ServiceConfig,
buffer: Option<Bytes>,
_t: PhantomData<(I, E)>,
_phantom: PhantomData<(I, E)>,
}
#[pin_project::pin_project(project = ServiceResponseStateProj)]
@ -199,8 +195,9 @@ where
skip_len = true;
*size = BodySize::Stream;
}
_ => (),
_ => {}
}
let _ = match size {
BodySize::None | BodySize::Stream => None,
BodySize::Empty => res
@ -215,11 +212,13 @@ where
// copy headers
for (key, value) in head.headers.iter() {
match *key {
CONNECTION | TRANSFER_ENCODING => continue, // http2 specific
// omit HTTP/1 only headers
CONNECTION | TRANSFER_ENCODING => continue,
CONTENT_LENGTH if skip_len => continue,
DATE => has_date = true,
_ => (),
_ => {}
}
res.headers_mut().append(key, value.clone());
}
@ -251,109 +250,117 @@ where
let mut this = self.as_mut().project();
match this.state.project() {
ServiceResponseStateProj::ServiceCall(call, send) => match call.poll(cx) {
Poll::Ready(Ok(res)) => {
let (res, body) = res.into().replace_body(());
ServiceResponseStateProj::ServiceCall(call, send) => {
match ready!(call.poll(cx)) {
Ok(res) => {
let (res, body) = res.into().replace_body(());
let mut send = send.take().unwrap();
let mut size = body.size();
let h2_res = self.as_mut().prepare_response(res.head(), &mut size);
this = self.as_mut().project();
let mut send = send.take().unwrap();
let mut size = body.size();
let h2_res =
self.as_mut().prepare_response(res.head(), &mut size);
this = self.as_mut().project();
let stream = match send.send_response(h2_res, size.is_eof()) {
Err(e) => {
trace!("Error sending h2 response: {:?}", e);
return Poll::Ready(());
let stream = match send.send_response(h2_res, size.is_eof()) {
Err(e) => {
trace!("Error sending HTTP/2 response: {:?}", e);
return Poll::Ready(());
}
Ok(stream) => stream,
};
if size.is_eof() {
Poll::Ready(())
} else {
this.state
.set(ServiceResponseState::SendPayload(stream, body));
self.poll(cx)
}
Ok(stream) => stream,
};
}
if size.is_eof() {
Poll::Ready(())
} else {
this.state
.set(ServiceResponseState::SendPayload(stream, body));
self.poll(cx)
Err(e) => {
let res: Response = e.into().into();
let (res, body) = res.replace_body(());
let mut send = send.take().unwrap();
let mut size = body.size();
let h2_res =
self.as_mut().prepare_response(res.head(), &mut size);
this = self.as_mut().project();
let stream = match send.send_response(h2_res, size.is_eof()) {
Err(e) => {
trace!("Error sending HTTP/2 response: {:?}", e);
return Poll::Ready(());
}
Ok(stream) => stream,
};
if size.is_eof() {
Poll::Ready(())
} else {
this.state.set(ServiceResponseState::SendPayload(
stream,
body.into_body(),
));
self.poll(cx)
}
}
}
Poll::Pending => Poll::Pending,
Poll::Ready(Err(e)) => {
let res: Response = e.into().into();
let (res, body) = res.replace_body(());
}
let mut send = send.take().unwrap();
let mut size = body.size();
let h2_res = self.as_mut().prepare_response(res.head(), &mut size);
this = self.as_mut().project();
let stream = match send.send_response(h2_res, size.is_eof()) {
Err(e) => {
trace!("Error sending h2 response: {:?}", e);
return Poll::Ready(());
}
Ok(stream) => stream,
};
if size.is_eof() {
Poll::Ready(())
} else {
this.state.set(ServiceResponseState::SendPayload(
stream,
body.into_body(),
));
self.poll(cx)
}
}
},
ServiceResponseStateProj::SendPayload(ref mut stream, ref mut body) => {
loop {
loop {
if let Some(ref mut buffer) = this.buffer {
match stream.poll_capacity(cx) {
Poll::Pending => return Poll::Pending,
Poll::Ready(None) => return Poll::Ready(()),
Poll::Ready(Some(Ok(cap))) => {
let len = buffer.len();
let bytes = buffer.split_to(std::cmp::min(cap, len));
match this.buffer {
Some(ref mut buffer) => {
match ready!(stream.poll_capacity(cx)) {
None => return Poll::Ready(()),
if let Err(e) = stream.send_data(bytes, false) {
Some(Ok(cap)) => {
let len = buffer.len();
let bytes = buffer.split_to(cmp::min(cap, len));
if let Err(e) = stream.send_data(bytes, false) {
warn!("{:?}", e);
return Poll::Ready(());
} else if !buffer.is_empty() {
let cap = cmp::min(buffer.len(), CHUNK_SIZE);
stream.reserve_capacity(cap);
} else {
this.buffer.take();
}
}
Some(Err(e)) => {
warn!("{:?}", e);
return Poll::Ready(());
} else if !buffer.is_empty() {
let cap =
std::cmp::min(buffer.len(), CHUNK_SIZE);
stream.reserve_capacity(cap);
} else {
this.buffer.take();
}
}
Poll::Ready(Some(Err(e))) => {
warn!("{:?}", e);
return Poll::Ready(());
}
}
} else {
match body.as_mut().poll_next(cx) {
Poll::Pending => return Poll::Pending,
Poll::Ready(None) => {
None => match ready!(body.as_mut().poll_next(cx)) {
None => {
if let Err(e) = stream.send_data(Bytes::new(), true)
{
warn!("{:?}", e);
}
return Poll::Ready(());
}
Poll::Ready(Some(Ok(chunk))) => {
stream.reserve_capacity(std::cmp::min(
Some(Ok(chunk)) => {
stream.reserve_capacity(cmp::min(
chunk.len(),
CHUNK_SIZE,
));
*this.buffer = Some(chunk);
}
Poll::Ready(Some(Err(e))) => {
Some(Err(e)) => {
error!("Response payload stream error: {:?}", e);
return Poll::Ready(());
}
}
},
}
}
}

View file

@ -1,9 +1,12 @@
//! HTTP/2 implementation
use std::pin::Pin;
use std::task::{Context, Poll};
//! HTTP/2 implementation.
use std::{
pin::Pin,
task::{Context, Poll},
};
use bytes::Bytes;
use futures_core::Stream;
use futures_core::{ready, Stream};
use h2::RecvStream;
mod dispatcher;
@ -13,14 +16,14 @@ pub use self::dispatcher::Dispatcher;
pub use self::service::H2Service;
use crate::error::PayloadError;
/// H2 receive stream
/// HTTP/2 peer stream.
pub struct Payload {
pl: RecvStream,
stream: RecvStream,
}
impl Payload {
pub(crate) fn new(pl: RecvStream) -> Self {
Self { pl }
pub(crate) fn new(stream: RecvStream) -> Self {
Self { stream }
}
}
@ -33,18 +36,17 @@ impl Stream for Payload {
) -> Poll<Option<Self::Item>> {
let this = self.get_mut();
match Pin::new(&mut this.pl).poll_data(cx) {
Poll::Ready(Some(Ok(chunk))) => {
match ready!(Pin::new(&mut this.stream).poll_data(cx)) {
Some(Ok(chunk)) => {
let len = chunk.len();
if let Err(err) = this.pl.flow_control().release_capacity(len) {
Poll::Ready(Some(Err(err.into())))
} else {
Poll::Ready(Some(Ok(chunk)))
match this.stream.flow_control().release_capacity(len) {
Ok(()) => Poll::Ready(Some(Ok(chunk))),
Err(err) => Poll::Ready(Some(Err(err.into()))),
}
}
Poll::Ready(Some(Err(err))) => Poll::Ready(Some(Err(err.into()))),
Poll::Pending => Poll::Pending,
Poll::Ready(None) => Poll::Ready(None),
Some(Err(err)) => Poll::Ready(Some(Err(err.into()))),
None => Poll::Ready(None),
}
}
}

View file

@ -26,12 +26,12 @@ use crate::{ConnectCallback, Extensions};
use super::dispatcher::Dispatcher;
/// `ServiceFactory` implementation for HTTP2 transport
/// `ServiceFactory` implementation for HTTP/2 transport
pub struct H2Service<T, S, B> {
srv: S,
cfg: ServiceConfig,
on_connect_ext: Option<Rc<ConnectCallback<T>>>,
_t: PhantomData<(T, B)>,
_phantom: PhantomData<(T, B)>,
}
impl<T, S, B> H2Service<T, S, B>
@ -42,7 +42,7 @@ where
<S::Service as Service<Request>>::Future: 'static,
B: MessageBody + 'static,
{
/// Create new `HttpService` instance with config.
/// Create new `H2Service` instance with config.
pub(crate) fn with_config<F: IntoServiceFactory<S, Request>>(
cfg: ServiceConfig,
service: F,
@ -51,7 +51,7 @@ where
cfg,
on_connect_ext: None,
srv: service.into_factory(),
_t: PhantomData,
_phantom: PhantomData,
}
}
@ -70,7 +70,7 @@ where
<S::Service as Service<Request>>::Future: 'static,
B: MessageBody + 'static,
{
/// Create simple tcp based service
/// Create plain TCP based service
pub fn tcp(
self,
) -> impl ServiceFactory<
@ -106,7 +106,7 @@ mod openssl {
<S::Service as Service<Request>>::Future: 'static,
B: MessageBody + 'static,
{
/// Create ssl based service
/// Create OpenSSL based service
pub fn openssl(
self,
acceptor: SslAcceptor,
@ -149,7 +149,7 @@ mod rustls {
<S::Service as Service<Request>>::Future: 'static,
B: MessageBody + 'static,
{
/// Create openssl based service
/// Create Rustls based service
pub fn rustls(
self,
mut config: ServerConfig,
@ -200,7 +200,7 @@ where
fut: self.srv.new_service(()),
cfg: Some(self.cfg.clone()),
on_connect_ext: self.on_connect_ext.clone(),
_t: PhantomData,
_phantom: PhantomData,
}
}
}
@ -215,7 +215,7 @@ where
fut: S::Future,
cfg: Option<ServiceConfig>,
on_connect_ext: Option<Rc<ConnectCallback<T>>>,
_t: PhantomData<B>,
_phantom: PhantomData<B>,
}
impl<T, S, B> Future for H2ServiceResponse<T, S, B>
@ -232,14 +232,14 @@ where
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.as_mut().project();
Poll::Ready(ready!(this.fut.poll(cx)).map(|service| {
this.fut.poll(cx).map_ok(|service| {
let this = self.as_mut().project();
H2ServiceHandler::new(
this.cfg.take().unwrap(),
this.on_connect_ext.clone(),
service,
)
}))
})
}
}
@ -251,7 +251,7 @@ where
srv: CloneableService<S>,
cfg: ServiceConfig,
on_connect_ext: Option<Rc<ConnectCallback<T>>>,
_t: PhantomData<B>,
_phantom: PhantomData<B>,
}
impl<T, S, B> H2ServiceHandler<T, S, B>
@ -271,7 +271,7 @@ where
cfg,
on_connect_ext,
srv: CloneableService::new(srv),
_t: PhantomData,
_phantom: PhantomData,
}
}
}
@ -363,8 +363,8 @@ where
ref peer_addr,
ref mut on_connect_data,
ref mut handshake,
) => match Pin::new(handshake).poll(cx) {
Poll::Ready(Ok(conn)) => {
) => match ready!(Pin::new(handshake).poll(cx)) {
Ok(conn) => {
self.state = State::Incoming(Dispatcher::new(
srv.take().unwrap(),
conn,
@ -375,11 +375,10 @@ where
));
self.poll(cx)
}
Poll::Ready(Err(err)) => {
Err(err) => {
trace!("H2 handshake error: {}", err);
Poll::Ready(Err(err.into()))
}
Poll::Pending => Poll::Pending,
},
}
}

View file

@ -28,7 +28,7 @@ pub struct HttpService<T, S, B, X = h1::ExpectHandler, U = h1::UpgradeHandler> {
expect: X,
upgrade: Option<U>,
on_connect_ext: Option<Rc<ConnectCallback<T>>>,
_t: PhantomData<B>,
_phantom: PhantomData<B>,
}
impl<T, S, B> HttpService<T, S, B>
@ -65,7 +65,7 @@ where
expect: h1::ExpectHandler,
upgrade: None,
on_connect_ext: None,
_t: PhantomData,
_phantom: PhantomData,
}
}
@ -80,7 +80,7 @@ where
expect: h1::ExpectHandler,
upgrade: None,
on_connect_ext: None,
_t: PhantomData,
_phantom: PhantomData,
}
}
}
@ -112,7 +112,7 @@ where
srv: self.srv,
upgrade: self.upgrade,
on_connect_ext: self.on_connect_ext,
_t: PhantomData,
_phantom: PhantomData,
}
}
@ -133,7 +133,7 @@ where
srv: self.srv,
expect: self.expect,
on_connect_ext: self.on_connect_ext,
_t: PhantomData,
_phantom: PhantomData,
}
}
@ -348,7 +348,7 @@ where
upgrade: None,
on_connect_ext: self.on_connect_ext.clone(),
cfg: self.cfg.clone(),
_t: PhantomData,
_phantom: PhantomData,
}
}
}
@ -371,7 +371,7 @@ where
upgrade: Option<U::Service>,
on_connect_ext: Option<Rc<ConnectCallback<T>>>,
cfg: ServiceConfig,
_t: PhantomData<(T, B)>,
_phantom: PhantomData<(T, B)>,
}
impl<T, S, B, X, U> Future for HttpServiceResponse<T, S, B, X, U>
@ -446,7 +446,7 @@ where
upgrade: Option<CloneableService<U>>,
cfg: ServiceConfig,
on_connect_ext: Option<Rc<ConnectCallback<T>>>,
_t: PhantomData<B>,
_phantom: PhantomData<B>,
}
impl<T, S, B, X, U> HttpServiceHandler<T, S, B, X, U>
@ -474,7 +474,7 @@ where
srv: CloneableService::new(srv),
expect: CloneableService::new(expect),
upgrade: upgrade.map(CloneableService::new),
_t: PhantomData,
_phantom: PhantomData,
}
}
}

View file

@ -184,7 +184,7 @@ impl Encoder<Message> for Codec {
}
}
},
Message::Nop => (),
Message::Nop => {},
}
Ok(())
}

View file

@ -125,7 +125,7 @@ impl Parser {
debug!("Received close frame with payload length exceeding 125. Morphing to protocol close frame.");
return Ok(Some((true, OpCode::Close, None)));
}
_ => (),
_ => {},
}
// unmask

View file

@ -222,7 +222,7 @@ mod test {
macro_rules! opcode_into {
($from:expr => $opcode:pat) => {
match OpCode::from($from) {
e @ $opcode => (),
e @ $opcode => {},
e => unreachable!("{:?}", e),
}
};
@ -232,7 +232,7 @@ mod test {
($from:expr => $opcode:pat) => {
let res: u8 = $from.into();
match res {
e @ $opcode => (),
e @ $opcode => {},
e => unreachable!("{:?}", e),
}
};

View file

@ -326,7 +326,7 @@ impl InnerMultipart {
}
}
}
_ => (),
_ => {},
}
// read field headers for next field
@ -835,7 +835,7 @@ mod tests {
async fn test_boundary() {
let headers = HeaderMap::new();
match Multipart::boundary(&headers) {
Err(MultipartError::NoContentType) => (),
Err(MultipartError::NoContentType) => {},
_ => unreachable!("should not happen"),
}
@ -846,7 +846,7 @@ mod tests {
);
match Multipart::boundary(&headers) {
Err(MultipartError::ParseContentType) => (),
Err(MultipartError::ParseContentType) => {},
_ => unreachable!("should not happen"),
}
@ -856,7 +856,7 @@ mod tests {
header::HeaderValue::from_static("multipart/mixed"),
);
match Multipart::boundary(&headers) {
Err(MultipartError::Boundary) => (),
Err(MultipartError::Boundary) => {},
_ => unreachable!("should not happen"),
}
@ -956,17 +956,17 @@ mod tests {
let mut multipart = Multipart::new(&headers, payload);
match multipart.next().await.unwrap() {
Ok(_) => (),
Ok(_) => {},
_ => unreachable!(),
}
match multipart.next().await.unwrap() {
Ok(_) => (),
Ok(_) => {},
_ => unreachable!(),
}
match multipart.next().await {
None => (),
None => {},
_ => unreachable!(),
}
}
@ -993,7 +993,7 @@ mod tests {
_ => unreachable!(),
}
match field.next().await {
None => (),
None => {},
_ => unreachable!(),
}
}
@ -1010,7 +1010,7 @@ mod tests {
_ => unreachable!(),
}
match field.next().await {
None => (),
None => {},
_ => unreachable!(),
}
}
@ -1018,7 +1018,7 @@ mod tests {
}
match multipart.next().await {
None => (),
None => {},
_ => unreachable!(),
}
}
@ -1066,7 +1066,7 @@ mod tests {
}
match multipart.next().await {
None => (),
None => {},
_ => unreachable!(),
}
}

View file

@ -21,7 +21,7 @@ impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for Ws {
ws::Message::Text(text) => ctx.text(text),
ws::Message::Binary(bin) => ctx.binary(bin),
ws::Message::Close(reason) => ctx.close(reason),
_ => (),
_ => {},
}
}
}

View file

@ -523,7 +523,7 @@ impl ClientRequest {
return Err(InvalidUrl::MissingScheme.into());
} else if let Some(scheme) = uri.scheme() {
match scheme.as_str() {
"http" | "ws" | "https" | "wss" => (),
"http" | "ws" | "https" | "wss" => {},
_ => return Err(InvalidUrl::UnknownScheme.into()),
}
} else {

View file

@ -234,7 +234,7 @@ pub struct JsonBody<S, U> {
length: Option<usize>,
err: Option<JsonPayloadError>,
fut: Option<ReadBody<S>>,
_t: PhantomData<U>,
_phantom: PhantomData<U>,
}
impl<S, U> JsonBody<S, U>
@ -255,7 +255,7 @@ where
length: None,
fut: None,
err: Some(JsonPayloadError::ContentType),
_t: PhantomData,
_phantom: PhantomData,
};
}
@ -272,7 +272,7 @@ where
length: len,
err: None,
fut: Some(ReadBody::new(req.take_payload(), 65536)),
_t: PhantomData,
_phantom: PhantomData,
}
}
@ -370,14 +370,14 @@ mod tests {
async fn test_body() {
let mut req = TestResponse::with_header(header::CONTENT_LENGTH, "xxxx").finish();
match req.body().await.err().unwrap() {
PayloadError::UnknownLength => (),
PayloadError::UnknownLength => {},
_ => unreachable!("error"),
}
let mut req =
TestResponse::with_header(header::CONTENT_LENGTH, "1000000").finish();
match req.body().await.err().unwrap() {
PayloadError::Overflow => (),
PayloadError::Overflow => {},
_ => unreachable!("error"),
}
@ -390,7 +390,7 @@ mod tests {
.set_payload(Bytes::from_static(b"11111111111111"))
.finish();
match req.body().limit(5).await.err().unwrap() {
PayloadError::Overflow => (),
PayloadError::Overflow => {},
_ => unreachable!("error"),
}
}

View file

@ -86,7 +86,7 @@ impl Future for SendClientRequest {
SendClientRequest::Fut(send, delay, response_decompress) => {
if delay.is_some() {
match Pin::new(delay.as_mut().unwrap()).poll(cx) {
Poll::Pending => (),
Poll::Pending => {},
_ => return Poll::Ready(Err(SendRequestError::Timeout)),
}
}
@ -127,7 +127,7 @@ impl Future for SendClientRequest {
SendClientRequest::Fut(send, delay, _) => {
if delay.is_some() {
match Pin::new(delay.as_mut().unwrap()).poll(cx) {
Poll::Pending => (),
Poll::Pending => {},
_ => return Poll::Ready(Err(SendRequestError::Timeout)),
}
}

View file

@ -259,7 +259,7 @@ impl WebsocketsRequest {
return Err(InvalidUrl::MissingScheme.into());
} else if let Some(scheme) = uri.scheme() {
match scheme.as_str() {
"http" | "ws" | "https" | "wss" => (),
"http" | "ws" | "https" | "wss" => {},
_ => return Err(InvalidUrl::UnknownScheme.into()),
}
} else {

View file

@ -127,7 +127,7 @@ async fn test_timeout() {
let request = client.get(srv.url("/")).send();
match request.await {
Err(SendRequestError::Timeout) => (),
Err(SendRequestError::Timeout) => {},
_ => panic!(),
}
}
@ -149,7 +149,7 @@ async fn test_timeout_override() {
.timeout(Duration::from_millis(50))
.send();
match request.await {
Err(SendRequestError::Timeout) => (),
Err(SendRequestError::Timeout) => {},
_ => panic!(),
}
}

View file

@ -38,7 +38,7 @@ pub struct App<T, B> {
data_factories: Vec<FnDataFactory>,
external: Vec<ResourceDef>,
extensions: Extensions,
_t: PhantomData<B>,
_phantom: PhantomData<B>,
}
impl App<AppEntry, Body> {
@ -55,7 +55,7 @@ impl App<AppEntry, Body> {
factory_ref: fref,
external: Vec::new(),
extensions: Extensions::new(),
_t: PhantomData,
_phantom: PhantomData,
}
}
}
@ -381,7 +381,7 @@ where
factory_ref: self.factory_ref,
external: self.external,
extensions: self.extensions,
_t: PhantomData,
_phantom: PhantomData,
}
}
@ -443,7 +443,7 @@ where
factory_ref: self.factory_ref,
external: self.external,
extensions: self.extensions,
_t: PhantomData,
_phantom: PhantomData,
}
}
}

View file

@ -123,7 +123,7 @@ where
),
config,
rmap,
_t: PhantomData,
_phantom: PhantomData,
}
}
}
@ -148,7 +148,7 @@ where
data: Rc<[Box<dyn DataFactory>]>,
extensions: Option<Extensions>,
_t: PhantomData<B>,
_phantom: PhantomData<B>,
}
impl<T, B> Future for AppInitResult<T, B>

View file

@ -49,7 +49,7 @@ where
R::Output: Responder,
{
hnd: F,
_t: PhantomData<(T, R)>,
_phantom: PhantomData<(T, R)>,
}
impl<F, T, R> HandlerService<F, T, R>
@ -62,7 +62,7 @@ where
pub fn new(hnd: F) -> Self {
Self {
hnd,
_t: PhantomData,
_phantom: PhantomData,
}
}
}
@ -77,7 +77,7 @@ where
fn clone(&self) -> Self {
Self {
hnd: self.hnd.clone(),
_t: PhantomData,
_phantom: PhantomData,
}
}
}

View file

@ -55,7 +55,7 @@ impl ConnectionInfo {
host = Some(val.trim());
}
}
_ => (),
_ => {},
}
}
}

View file

@ -104,7 +104,7 @@ where
CompressResponse {
encoding,
fut: self.service.call(req),
_t: PhantomData,
_phantom: PhantomData,
}
}
}
@ -119,7 +119,7 @@ where
#[pin]
fut: S::Future,
encoding: ContentEncoding,
_t: PhantomData<B>,
_phantom: PhantomData<B>,
}
impl<S, B> Future for CompressResponse<S, B>

View file

@ -236,7 +236,7 @@ where
fut: self.service.call(req),
format: None,
time: OffsetDateTime::now_utc(),
_t: PhantomData,
_phantom: PhantomData,
}
} else {
let now = OffsetDateTime::now_utc();
@ -249,7 +249,7 @@ where
fut: self.service.call(req),
format: Some(format),
time: now,
_t: PhantomData,
_phantom: PhantomData,
}
}
}
@ -266,7 +266,7 @@ where
fut: S::Future,
time: OffsetDateTime,
format: Option<Format>,
_t: PhantomData<B>,
_phantom: PhantomData<B>,
}
impl<S, B> Future for LoggerResponse<S, B>
@ -522,7 +522,7 @@ impl FormatText {
};
*self = FormatText::Str(s.to_string())
}
_ => (),
_ => {},
}
}
@ -587,7 +587,7 @@ impl FormatText {
*self = s;
}
_ => (),
_ => {},
}
}
}

View file

@ -349,14 +349,14 @@ where
pub struct ResponseFuture<T, E> {
#[pin]
fut: T,
_t: PhantomData<E>,
_phantom: PhantomData<E>,
}
impl<T, E> ResponseFuture<T, E> {
pub fn new(fut: T) -> Self {
ResponseFuture {
fut,
_t: PhantomData,
_phantom: PhantomData,
}
}
}

View file

@ -1,6 +1,6 @@
use std::{
any::Any,
fmt, io,
cmp, fmt, io,
marker::PhantomData,
net,
sync::{Arc, Mutex},
@ -71,7 +71,7 @@ where
sockets: Vec<Socket>,
builder: ServerBuilder,
on_connect_fn: Option<Arc<dyn Fn(&dyn Any, &mut Extensions) + Send + Sync>>,
_t: PhantomData<(S, B)>,
_phantom: PhantomData<(S, B)>,
}
impl<F, I, S, B> HttpServer<F, I, S, B>
@ -100,7 +100,7 @@ where
sockets: Vec::new(),
builder: ServerBuilder::default(),
on_connect_fn: None,
_t: PhantomData,
_phantom: PhantomData,
}
}
@ -125,7 +125,7 @@ where
sockets: self.sockets,
builder: self.builder,
on_connect_fn: Some(Arc::new(f)),
_t: PhantomData,
_phantom: PhantomData,
}
}
@ -653,7 +653,7 @@ fn create_tcp_listener(
socket.set_reuse_address(true)?;
socket.bind(&addr.into())?;
// clamp backlog to max u32 that fits in i32 range
let backlog = backlog.min(i32::MAX as u32) as i32;
let backlog = cmp::min(backlog, i32::MAX as u32) as i32;
socket.listen(backlog)?;
Ok(socket.into_tcp_listener())
}

View file

@ -539,7 +539,7 @@ mod tests {
.into_parts();
let res = HttpMessageBody::new(&req, &mut pl).await;
match res.err().unwrap() {
PayloadError::UnknownLength => (),
PayloadError::UnknownLength => {},
_ => unreachable!("error"),
}
@ -548,7 +548,7 @@ mod tests {
.into_parts();
let res = HttpMessageBody::new(&req, &mut pl).await;
match res.err().unwrap() {
PayloadError::Overflow => (),
PayloadError::Overflow => {},
_ => unreachable!("error"),
}
@ -563,7 +563,7 @@ mod tests {
.to_http_parts();
let res = HttpMessageBody::new(&req, &mut pl).limit(5).await;
match res.err().unwrap() {
PayloadError::Overflow => (),
PayloadError::Overflow => {},
_ => unreachable!("error"),
}
}