1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-12-18 01:33:59 +01:00

nightly clippy warnings

This commit is contained in:
Nikolay Kim 2019-07-17 15:48:37 +06:00
parent 4092c7f326
commit 2a2d7f5768
34 changed files with 104 additions and 99 deletions

View File

@ -75,7 +75,7 @@ actix-utils = "0.4.4"
actix-router = "0.1.5" actix-router = "0.1.5"
actix-rt = "0.2.4" actix-rt = "0.2.4"
actix-web-codegen = "0.1.2" actix-web-codegen = "0.1.2"
actix-http = "0.2.5" actix-http = "0.2.6"
actix-server = "0.5.1" actix-server = "0.5.1"
actix-server-config = "0.1.1" actix-server-config = "0.1.1"
actix-threadpool = "0.1.1" actix-threadpool = "0.1.1"
@ -89,7 +89,7 @@ hashbrown = "0.5.0"
log = "0.4" log = "0.4"
mime = "0.3" mime = "0.3"
net2 = "0.2.33" net2 = "0.2.33"
parking_lot = "0.8" parking_lot = "0.9"
regex = "1.0" regex = "1.0"
serde = { version = "1.0", features=["derive"] } serde = { version = "1.0", features=["derive"] }
serde_json = "1.0" serde_json = "1.0"

View File

@ -587,10 +587,10 @@ impl Inner {
} }
Err(CorsError::BadOrigin) Err(CorsError::BadOrigin)
} else { } else {
return match self.origins { match self.origins {
AllOrSome::All => Ok(()), AllOrSome::All => Ok(()),
_ => Err(CorsError::MissingOrigin), _ => Err(CorsError::MissingOrigin),
}; }
} }
} }
@ -665,7 +665,7 @@ impl Inner {
} }
Err(CorsError::BadRequestHeaders) Err(CorsError::BadRequestHeaders)
} else { } else {
return Ok(()); Ok(())
} }
} }
} }

View File

@ -107,7 +107,7 @@ impl Stream for ChunkedReadFile {
} }
type DirectoryRenderer = type DirectoryRenderer =
Fn(&Directory, &HttpRequest) -> Result<ServiceResponse, io::Error>; dyn Fn(&Directory, &HttpRequest) -> Result<ServiceResponse, io::Error>;
/// A directory; responds with the generated directory listing. /// A directory; responds with the generated directory listing.
#[derive(Debug)] #[derive(Debug)]
@ -211,7 +211,7 @@ fn directory_listing(
)) ))
} }
type MimeOverride = Fn(&mime::Name) -> DispositionType; type MimeOverride = dyn Fn(&mime::Name) -> DispositionType;
/// Static files handling /// Static files handling
/// ///
@ -475,7 +475,7 @@ impl Service for FilesService {
Err(e) => ServiceResponse::from_err(e, req), Err(e) => ServiceResponse::from_err(e, req),
})) }))
} }
Err(e) => return self.handle_err(e, req), Err(e) => self.handle_err(e, req),
} }
} else if self.show_index { } else if self.show_index {
let dir = Directory::new(self.directory.clone(), path); let dir = Directory::new(self.directory.clone(), path);
@ -483,7 +483,7 @@ impl Service for FilesService {
let x = (self.renderer)(&dir, &req); let x = (self.renderer)(&dir, &req);
match x { match x {
Ok(resp) => Either::A(ok(resp)), Ok(resp) => Either::A(ok(resp)),
Err(e) => return Either::A(ok(ServiceResponse::from_err(e, req))), Err(e) => Either::A(ok(ServiceResponse::from_err(e, req))),
} }
} else { } else {
Either::A(ok(ServiceResponse::from_err( Either::A(ok(ServiceResponse::from_err(
@ -857,7 +857,7 @@ mod tests {
#[test] #[test]
fn test_named_file_content_length_headers() { fn test_named_file_content_length_headers() {
use actix_web::body::{MessageBody, ResponseBody}; // use actix_web::body::{MessageBody, ResponseBody};
let mut srv = test::init_service( let mut srv = test::init_service(
App::new().service(Files::new("test", ".").index_file("tests/test.binary")), App::new().service(Files::new("test", ".").index_file("tests/test.binary")),
@ -868,7 +868,7 @@ mod tests {
.uri("/t%65st/tests/test.binary") .uri("/t%65st/tests/test.binary")
.header(header::RANGE, "bytes=10-20") .header(header::RANGE, "bytes=10-20")
.to_request(); .to_request();
let response = test::call_service(&mut srv, request); let _response = test::call_service(&mut srv, request);
// let contentlength = response // let contentlength = response
// .headers() // .headers()
@ -891,7 +891,7 @@ mod tests {
.uri("/t%65st/tests/test.binary") .uri("/t%65st/tests/test.binary")
// .no_default_headers() // .no_default_headers()
.to_request(); .to_request();
let response = test::call_service(&mut srv, request); let _response = test::call_service(&mut srv, request);
// let contentlength = response // let contentlength = response
// .headers() // .headers()
@ -939,7 +939,7 @@ mod tests {
.method(Method::HEAD) .method(Method::HEAD)
.uri("/t%65st/tests/test.binary") .uri("/t%65st/tests/test.binary")
.to_request(); .to_request();
let response = test::call_service(&mut srv, request); let _response = test::call_service(&mut srv, request);
// TODO: fix check // TODO: fix check
// let contentlength = response // let contentlength = response

View File

@ -5,7 +5,7 @@ pub struct HttpRange {
pub length: u64, pub length: u64,
} }
static PREFIX: &'static str = "bytes="; static PREFIX: &str = "bytes=";
const PREFIX_LEN: usize = 6; const PREFIX_LEN: usize = 6;
impl HttpRange { impl HttpRange {

View File

@ -3,7 +3,7 @@ use actix_service::{NewService, Service};
use futures::{Future, Poll}; use futures::{Future, Poll};
pub(crate) type BoxedHttpService<Req> = Box< pub(crate) type BoxedHttpService<Req> = Box<
Service< dyn Service<
Request = Req, Request = Req,
Response = (), Response = (),
Error = Error, Error = Error,
@ -12,7 +12,7 @@ pub(crate) type BoxedHttpService<Req> = Box<
>; >;
pub(crate) type BoxedHttpNewService<Req> = Box< pub(crate) type BoxedHttpNewService<Req> = Box<
NewService< dyn NewService<
Config = (), Config = (),
Request = Req, Request = Req,
Response = (), Response = (),

View File

@ -26,7 +26,7 @@ pub struct HttpServiceBuilder<T, S, X = ExpectHandler, U = UpgradeHandler<T>> {
client_disconnect: u64, client_disconnect: u64,
expect: X, expect: X,
upgrade: Option<U>, upgrade: Option<U>,
on_connect: Option<Rc<Fn(&T) -> Box<dyn DataFactory>>>, on_connect: Option<Rc<dyn Fn(&T) -> Box<dyn DataFactory>>>,
_t: PhantomData<(T, S)>, _t: PhantomData<(T, S)>,
} }

View File

@ -130,7 +130,7 @@ where
type TunnelFuture = Either< type TunnelFuture = Either<
Box< Box<
Future< dyn Future<
Item = (ResponseHead, Framed<Self::Io, ClientCodec>), Item = (ResponseHead, Framed<Self::Io, ClientCodec>),
Error = SendRequestError, Error = SendRequestError,
>, >,
@ -192,7 +192,7 @@ where
} }
type TunnelFuture = Box< type TunnelFuture = Box<
Future< dyn Future<
Item = (ResponseHead, Framed<Self::Io, ClientCodec>), Item = (ResponseHead, Framed<Self::Io, ClientCodec>),
Error = SendRequestError, Error = SendRequestError,
>, >,

View File

@ -6,7 +6,7 @@ use ring::rand::{SecureRandom, SystemRandom};
use super::private::KEY_LEN as PRIVATE_KEY_LEN; use super::private::KEY_LEN as PRIVATE_KEY_LEN;
use super::signed::KEY_LEN as SIGNED_KEY_LEN; use super::signed::KEY_LEN as SIGNED_KEY_LEN;
static HKDF_DIGEST: &'static Algorithm = &SHA256; static HKDF_DIGEST: &Algorithm = &SHA256;
const KEYS_INFO: &str = "COOKIE;SIGNED:HMAC-SHA256;PRIVATE:AEAD-AES-256-GCM"; const KEYS_INFO: &str = "COOKIE;SIGNED:HMAC-SHA256;PRIVATE:AEAD-AES-256-GCM";
/// A cryptographic master key for use with `Signed` and/or `Private` jars. /// A cryptographic master key for use with `Signed` and/or `Private` jars.

View File

@ -10,7 +10,7 @@ use crate::cookie::{Cookie, CookieJar};
// Keep these in sync, and keep the key len synced with the `private` docs as // Keep these in sync, and keep the key len synced with the `private` docs as
// well as the `KEYS_INFO` const in secure::Key. // well as the `KEYS_INFO` const in secure::Key.
static ALGO: &'static Algorithm = &AES_256_GCM; static ALGO: &Algorithm = &AES_256_GCM;
const NONCE_LEN: usize = 12; const NONCE_LEN: usize = 12;
pub const KEY_LEN: usize = 32; pub const KEY_LEN: usize = 32;

View File

@ -6,7 +6,7 @@ use crate::cookie::{Cookie, CookieJar};
// Keep these in sync, and keep the key len synced with the `signed` docs as // Keep these in sync, and keep the key len synced with the `signed` docs as
// well as the `KEYS_INFO` const in secure::Key. // well as the `KEYS_INFO` const in secure::Key.
static HMAC_DIGEST: &'static Algorithm = &SHA256; static HMAC_DIGEST: &Algorithm = &SHA256;
const BASE64_DIGEST_LEN: usize = 44; const BASE64_DIGEST_LEN: usize = 44;
pub const KEY_LEN: usize = 32; pub const KEY_LEN: usize = 32;

View File

@ -43,12 +43,12 @@ pub type Result<T, E = Error> = result::Result<T, E>;
/// if you have access to an actix `Error` you can always get a /// if you have access to an actix `Error` you can always get a
/// `ResponseError` reference from it. /// `ResponseError` reference from it.
pub struct Error { pub struct Error {
cause: Box<ResponseError>, cause: Box<dyn ResponseError>,
} }
impl Error { impl Error {
/// Returns the reference to the underlying `ResponseError`. /// Returns the reference to the underlying `ResponseError`.
pub fn as_response_error(&self) -> &ResponseError { pub fn as_response_error(&self) -> &dyn ResponseError {
self.cause.as_ref() self.cause.as_ref()
} }
} }

View File

@ -6,7 +6,7 @@ use hashbrown::HashMap;
#[derive(Default)] #[derive(Default)]
/// A type map of request extensions. /// A type map of request extensions.
pub struct Extensions { pub struct Extensions {
map: HashMap<TypeId, Box<Any>>, map: HashMap<TypeId, Box<dyn Any>>,
} }
impl Extensions { impl Extensions {
@ -35,14 +35,14 @@ impl Extensions {
pub fn get<T: 'static>(&self) -> Option<&T> { pub fn get<T: 'static>(&self) -> Option<&T> {
self.map self.map
.get(&TypeId::of::<T>()) .get(&TypeId::of::<T>())
.and_then(|boxed| (&**boxed as &(Any + 'static)).downcast_ref()) .and_then(|boxed| (&**boxed as &(dyn Any + 'static)).downcast_ref())
} }
/// Get a mutable reference to a type previously inserted on this `Extensions`. /// Get a mutable reference to a type previously inserted on this `Extensions`.
pub fn get_mut<T: 'static>(&mut self) -> Option<&mut T> { pub fn get_mut<T: 'static>(&mut self) -> Option<&mut T> {
self.map self.map
.get_mut(&TypeId::of::<T>()) .get_mut(&TypeId::of::<T>())
.and_then(|boxed| (&mut **boxed as &mut (Any + 'static)).downcast_mut()) .and_then(|boxed| (&mut **boxed as &mut (dyn Any + 'static)).downcast_mut())
} }
/// Remove a type from this `Extensions`. /// Remove a type from this `Extensions`.
@ -50,7 +50,7 @@ impl Extensions {
/// If a extension of this type existed, it will be returned. /// If a extension of this type existed, it will be returned.
pub fn remove<T: 'static>(&mut self) -> Option<T> { pub fn remove<T: 'static>(&mut self) -> Option<T> {
self.map.remove(&TypeId::of::<T>()).and_then(|boxed| { self.map.remove(&TypeId::of::<T>()).and_then(|boxed| {
(boxed as Box<Any + 'static>) (boxed as Box<dyn Any + 'static>)
.downcast() .downcast()
.ok() .ok()
.map(|boxed| *boxed) .map(|boxed| *boxed)

View File

@ -502,15 +502,15 @@ impl ChunkedState {
fn read_size(rdr: &mut BytesMut, size: &mut u64) -> Poll<ChunkedState, io::Error> { fn read_size(rdr: &mut BytesMut, size: &mut u64) -> Poll<ChunkedState, io::Error> {
let radix = 16; let radix = 16;
match byte!(rdr) { match byte!(rdr) {
b @ b'0'...b'9' => { b @ b'0'..=b'9' => {
*size *= radix; *size *= radix;
*size += u64::from(b - b'0'); *size += u64::from(b - b'0');
} }
b @ b'a'...b'f' => { b @ b'a'..=b'f' => {
*size *= radix; *size *= radix;
*size += u64::from(b + 10 - b'a'); *size += u64::from(b + 10 - b'a');
} }
b @ b'A'...b'F' => { b @ b'A'..=b'F' => {
*size *= radix; *size *= radix;
*size += u64::from(b + 10 - b'A'); *size += u64::from(b + 10 - b'A');
} }

View File

@ -26,7 +26,7 @@ pub struct H1Service<T, P, S, B, X = ExpectHandler, U = UpgradeHandler<T>> {
cfg: ServiceConfig, cfg: ServiceConfig,
expect: X, expect: X,
upgrade: Option<U>, upgrade: Option<U>,
on_connect: Option<Rc<Fn(&T) -> Box<dyn DataFactory>>>, on_connect: Option<Rc<dyn Fn(&T) -> Box<dyn DataFactory>>>,
_t: PhantomData<(T, P, B)>, _t: PhantomData<(T, P, B)>,
} }
@ -108,7 +108,7 @@ where
/// Set on connect callback. /// Set on connect callback.
pub(crate) fn on_connect( pub(crate) fn on_connect(
mut self, mut self,
f: Option<Rc<Fn(&T) -> Box<dyn DataFactory>>>, f: Option<Rc<dyn Fn(&T) -> Box<dyn DataFactory>>>,
) -> Self { ) -> Self {
self.on_connect = f; self.on_connect = f;
self self
@ -174,7 +174,7 @@ where
fut_upg: Option<U::Future>, fut_upg: Option<U::Future>,
expect: Option<X::Service>, expect: Option<X::Service>,
upgrade: Option<U::Service>, upgrade: Option<U::Service>,
on_connect: Option<Rc<Fn(&T) -> Box<dyn DataFactory>>>, on_connect: Option<Rc<dyn Fn(&T) -> Box<dyn DataFactory>>>,
cfg: Option<ServiceConfig>, cfg: Option<ServiceConfig>,
_t: PhantomData<(T, P, B)>, _t: PhantomData<(T, P, B)>,
} }
@ -233,7 +233,7 @@ pub struct H1ServiceHandler<T, P, S, B, X, U> {
srv: CloneableService<S>, srv: CloneableService<S>,
expect: CloneableService<X>, expect: CloneableService<X>,
upgrade: Option<CloneableService<U>>, upgrade: Option<CloneableService<U>>,
on_connect: Option<Rc<Fn(&T) -> Box<dyn DataFactory>>>, on_connect: Option<Rc<dyn Fn(&T) -> Box<dyn DataFactory>>>,
cfg: ServiceConfig, cfg: ServiceConfig,
_t: PhantomData<(T, P, B)>, _t: PhantomData<(T, P, B)>,
} }
@ -254,7 +254,7 @@ where
srv: S, srv: S,
expect: X, expect: X,
upgrade: Option<U>, upgrade: Option<U>,
on_connect: Option<Rc<Fn(&T) -> Box<dyn DataFactory>>>, on_connect: Option<Rc<dyn Fn(&T) -> Box<dyn DataFactory>>>,
) -> H1ServiceHandler<T, P, S, B, X, U> { ) -> H1ServiceHandler<T, P, S, B, X, U> {
H1ServiceHandler { H1ServiceHandler {
srv: CloneableService::new(srv), srv: CloneableService::new(srv),

View File

@ -27,7 +27,7 @@ use super::dispatcher::Dispatcher;
pub struct H2Service<T, P, S, B> { pub struct H2Service<T, P, S, B> {
srv: S, srv: S,
cfg: ServiceConfig, cfg: ServiceConfig,
on_connect: Option<rc::Rc<Fn(&T) -> Box<dyn DataFactory>>>, on_connect: Option<rc::Rc<dyn Fn(&T) -> Box<dyn DataFactory>>>,
_t: PhantomData<(T, P, B)>, _t: PhantomData<(T, P, B)>,
} }
@ -64,7 +64,7 @@ where
/// Set on connect callback. /// Set on connect callback.
pub(crate) fn on_connect( pub(crate) fn on_connect(
mut self, mut self,
f: Option<rc::Rc<Fn(&T) -> Box<dyn DataFactory>>>, f: Option<rc::Rc<dyn Fn(&T) -> Box<dyn DataFactory>>>,
) -> Self { ) -> Self {
self.on_connect = f; self.on_connect = f;
self self
@ -102,7 +102,7 @@ where
pub struct H2ServiceResponse<T, P, S: NewService, B> { pub struct H2ServiceResponse<T, P, S: NewService, B> {
fut: <S::Future as IntoFuture>::Future, fut: <S::Future as IntoFuture>::Future,
cfg: Option<ServiceConfig>, cfg: Option<ServiceConfig>,
on_connect: Option<rc::Rc<Fn(&T) -> Box<dyn DataFactory>>>, on_connect: Option<rc::Rc<dyn Fn(&T) -> Box<dyn DataFactory>>>,
_t: PhantomData<(T, P, B)>, _t: PhantomData<(T, P, B)>,
} }
@ -132,7 +132,7 @@ where
pub struct H2ServiceHandler<T, P, S, B> { pub struct H2ServiceHandler<T, P, S, B> {
srv: CloneableService<S>, srv: CloneableService<S>,
cfg: ServiceConfig, cfg: ServiceConfig,
on_connect: Option<rc::Rc<Fn(&T) -> Box<dyn DataFactory>>>, on_connect: Option<rc::Rc<dyn Fn(&T) -> Box<dyn DataFactory>>>,
_t: PhantomData<(T, P, B)>, _t: PhantomData<(T, P, B)>,
} }
@ -146,7 +146,7 @@ where
{ {
fn new( fn new(
cfg: ServiceConfig, cfg: ServiceConfig,
on_connect: Option<rc::Rc<Fn(&T) -> Box<dyn DataFactory>>>, on_connect: Option<rc::Rc<dyn Fn(&T) -> Box<dyn DataFactory>>>,
srv: S, srv: S,
) -> H2ServiceHandler<T, P, S, B> { ) -> H2ServiceHandler<T, P, S, B> {
H2ServiceHandler { H2ServiceHandler {

View File

@ -26,7 +26,7 @@ pub struct HttpService<T, P, S, B, X = h1::ExpectHandler, U = h1::UpgradeHandler
cfg: ServiceConfig, cfg: ServiceConfig,
expect: X, expect: X,
upgrade: Option<U>, upgrade: Option<U>,
on_connect: Option<rc::Rc<Fn(&T) -> Box<dyn DataFactory>>>, on_connect: Option<rc::Rc<dyn Fn(&T) -> Box<dyn DataFactory>>>,
_t: PhantomData<(T, P, B)>, _t: PhantomData<(T, P, B)>,
} }
@ -140,7 +140,7 @@ where
/// Set on connect callback. /// Set on connect callback.
pub(crate) fn on_connect( pub(crate) fn on_connect(
mut self, mut self,
f: Option<rc::Rc<Fn(&T) -> Box<dyn DataFactory>>>, f: Option<rc::Rc<dyn Fn(&T) -> Box<dyn DataFactory>>>,
) -> Self { ) -> Self {
self.on_connect = f; self.on_connect = f;
self self
@ -196,7 +196,7 @@ pub struct HttpServiceResponse<T, P, S: NewService, B, X: NewService, U: NewServ
fut_upg: Option<U::Future>, fut_upg: Option<U::Future>,
expect: Option<X::Service>, expect: Option<X::Service>,
upgrade: Option<U::Service>, upgrade: Option<U::Service>,
on_connect: Option<rc::Rc<Fn(&T) -> Box<dyn DataFactory>>>, on_connect: Option<rc::Rc<dyn Fn(&T) -> Box<dyn DataFactory>>>,
cfg: Option<ServiceConfig>, cfg: Option<ServiceConfig>,
_t: PhantomData<(T, P, B)>, _t: PhantomData<(T, P, B)>,
} }
@ -257,7 +257,7 @@ pub struct HttpServiceHandler<T, P, S, B, X, U> {
expect: CloneableService<X>, expect: CloneableService<X>,
upgrade: Option<CloneableService<U>>, upgrade: Option<CloneableService<U>>,
cfg: ServiceConfig, cfg: ServiceConfig,
on_connect: Option<rc::Rc<Fn(&T) -> Box<dyn DataFactory>>>, on_connect: Option<rc::Rc<dyn Fn(&T) -> Box<dyn DataFactory>>>,
_t: PhantomData<(T, P, B, X)>, _t: PhantomData<(T, P, B, X)>,
} }
@ -278,7 +278,7 @@ where
srv: S, srv: S,
expect: X, expect: X,
upgrade: Option<U>, upgrade: Option<U>,
on_connect: Option<rc::Rc<Fn(&T) -> Box<dyn DataFactory>>>, on_connect: Option<rc::Rc<dyn Fn(&T) -> Box<dyn DataFactory>>>,
) -> HttpServiceHandler<T, P, S, B, X, U> { ) -> HttpServiceHandler<T, P, S, B, X, U> {
HttpServiceHandler { HttpServiceHandler {
cfg, cfg,

View File

@ -203,7 +203,7 @@ impl<T: Into<String>> From<(CloseCode, T)> for CloseReason {
} }
} }
static WS_GUID: &'static str = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; static WS_GUID: &str = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
// TODO: hash is always same size, we dont need String // TODO: hash is always same size, we dont need String
pub fn hash_key(key: &[u8]) -> String { pub fn hash_key(key: &[u8]) -> String {

View File

@ -283,7 +283,7 @@ where
res.request().extensions_mut().remove::<IdentityItem>(); res.request().extensions_mut().remove::<IdentityItem>();
if let Some(id) = id { if let Some(id) = id {
return Either::A( Either::A(
backend backend
.to_response(id.id, id.changed, &mut res) .to_response(id.id, id.changed, &mut res)
.into_future() .into_future()
@ -291,7 +291,7 @@ where
Ok(_) => Ok(res), Ok(_) => Ok(res),
Err(e) => Ok(res.error_response(e)), Err(e) => Ok(res.error_response(e)),
}), }),
); )
} else { } else {
Either::B(ok(res)) Either::B(ok(res))
} }

View File

@ -282,7 +282,7 @@ mod tests {
#[test] #[test]
fn purge_session() { fn purge_session() {
let mut req = test::TestRequest::default().to_srv_request(); let req = test::TestRequest::default().to_srv_request();
let session = Session::get_session(&mut *req.extensions_mut()); let session = Session::get_session(&mut *req.extensions_mut());
assert_eq!(session.0.borrow().status, SessionStatus::Unchanged); assert_eq!(session.0.borrow().status, SessionStatus::Unchanged);
session.purge(); session.purge();
@ -291,7 +291,7 @@ mod tests {
#[test] #[test]
fn renew_session() { fn renew_session() {
let mut req = test::TestRequest::default().to_srv_request(); let req = test::TestRequest::default().to_srv_request();
let session = Session::get_session(&mut *req.extensions_mut()); let session = Session::get_session(&mut *req.extensions_mut());
assert_eq!(session.0.borrow().status, SessionStatus::Unchanged); assert_eq!(session.0.borrow().status, SessionStatus::Unchanged);
session.renew(); session.renew();

View File

@ -28,7 +28,7 @@ pub(crate) trait Connect {
head: RequestHead, head: RequestHead,
addr: Option<net::SocketAddr>, addr: Option<net::SocketAddr>,
) -> Box< ) -> Box<
Future< dyn Future<
Item = (ResponseHead, Framed<BoxedSocket, ClientCodec>), Item = (ResponseHead, Framed<BoxedSocket, ClientCodec>),
Error = SendRequestError, Error = SendRequestError,
>, >,
@ -69,7 +69,7 @@ where
head: RequestHead, head: RequestHead,
addr: Option<net::SocketAddr>, addr: Option<net::SocketAddr>,
) -> Box< ) -> Box<
Future< dyn Future<
Item = (ResponseHead, Framed<BoxedSocket, ClientCodec>), Item = (ResponseHead, Framed<BoxedSocket, ClientCodec>),
Error = SendRequestError, Error = SendRequestError,
>, >,
@ -93,21 +93,21 @@ where
} }
trait AsyncSocket { trait AsyncSocket {
fn as_read(&self) -> &AsyncRead; fn as_read(&self) -> &dyn AsyncRead;
fn as_read_mut(&mut self) -> &mut AsyncRead; fn as_read_mut(&mut self) -> &mut dyn AsyncRead;
fn as_write(&mut self) -> &mut AsyncWrite; fn as_write(&mut self) -> &mut dyn AsyncWrite;
} }
struct Socket<T: AsyncRead + AsyncWrite>(T); struct Socket<T: AsyncRead + AsyncWrite>(T);
impl<T: AsyncRead + AsyncWrite> AsyncSocket for Socket<T> { impl<T: AsyncRead + AsyncWrite> AsyncSocket for Socket<T> {
fn as_read(&self) -> &AsyncRead { fn as_read(&self) -> &dyn AsyncRead {
&self.0 &self.0
} }
fn as_read_mut(&mut self) -> &mut AsyncRead { fn as_read_mut(&mut self) -> &mut dyn AsyncRead {
&mut self.0 &mut self.0
} }
fn as_write(&mut self) -> &mut AsyncWrite { fn as_write(&mut self) -> &mut dyn AsyncWrite {
&mut self.0 &mut self.0
} }
} }

View File

@ -23,16 +23,17 @@ use crate::service::{
}; };
type HttpNewService = BoxedNewService<(), ServiceRequest, ServiceResponse, Error, ()>; type HttpNewService = BoxedNewService<(), ServiceRequest, ServiceResponse, Error, ()>;
type FnDataFactory = Box<Fn() -> Box<dyn Future<Item = Box<DataFactory>, Error = ()>>>; type FnDataFactory =
Box<dyn Fn() -> Box<dyn Future<Item = Box<dyn DataFactory>, Error = ()>>>;
/// Application builder - structure that follows the builder pattern /// Application builder - structure that follows the builder pattern
/// for building application instances. /// for building application instances.
pub struct App<T, B> { pub struct App<T, B> {
endpoint: T, endpoint: T,
services: Vec<Box<ServiceFactory>>, services: Vec<Box<dyn ServiceFactory>>,
default: Option<Rc<HttpNewService>>, default: Option<Rc<HttpNewService>>,
factory_ref: Rc<RefCell<Option<AppRoutingFactory>>>, factory_ref: Rc<RefCell<Option<AppRoutingFactory>>>,
data: Vec<Box<DataFactory>>, data: Vec<Box<dyn DataFactory>>,
data_factories: Vec<FnDataFactory>, data_factories: Vec<FnDataFactory>,
config: AppConfigInner, config: AppConfigInner,
external: Vec<ResourceDef>, external: Vec<ResourceDef>,

View File

@ -18,14 +18,15 @@ use crate::request::{HttpRequest, HttpRequestPool};
use crate::rmap::ResourceMap; use crate::rmap::ResourceMap;
use crate::service::{ServiceFactory, ServiceRequest, ServiceResponse}; use crate::service::{ServiceFactory, ServiceRequest, ServiceResponse};
type Guards = Vec<Box<Guard>>; type Guards = Vec<Box<dyn Guard>>;
type HttpService = BoxedService<ServiceRequest, ServiceResponse, Error>; type HttpService = BoxedService<ServiceRequest, ServiceResponse, Error>;
type HttpNewService = BoxedNewService<(), ServiceRequest, ServiceResponse, Error, ()>; type HttpNewService = BoxedNewService<(), ServiceRequest, ServiceResponse, Error, ()>;
type BoxedResponse = Either< type BoxedResponse = Either<
FutureResult<ServiceResponse, Error>, FutureResult<ServiceResponse, Error>,
Box<dyn Future<Item = ServiceResponse, Error = Error>>, Box<dyn Future<Item = ServiceResponse, Error = Error>>,
>; >;
type FnDataFactory = Box<Fn() -> Box<dyn Future<Item = Box<DataFactory>, Error = ()>>>; type FnDataFactory =
Box<dyn Fn() -> Box<dyn Future<Item = Box<dyn DataFactory>, Error = ()>>>;
/// Service factory to convert `Request` to a `ServiceRequest<S>`. /// Service factory to convert `Request` to a `ServiceRequest<S>`.
/// It also executes data factories. /// It also executes data factories.
@ -40,10 +41,10 @@ where
>, >,
{ {
pub(crate) endpoint: T, pub(crate) endpoint: T,
pub(crate) data: Rc<Vec<Box<DataFactory>>>, pub(crate) data: Rc<Vec<Box<dyn DataFactory>>>,
pub(crate) data_factories: Rc<Vec<FnDataFactory>>, pub(crate) data_factories: Rc<Vec<FnDataFactory>>,
pub(crate) config: RefCell<AppConfig>, pub(crate) config: RefCell<AppConfig>,
pub(crate) services: Rc<RefCell<Vec<Box<ServiceFactory>>>>, pub(crate) services: Rc<RefCell<Vec<Box<dyn ServiceFactory>>>>,
pub(crate) default: Option<Rc<HttpNewService>>, pub(crate) default: Option<Rc<HttpNewService>>,
pub(crate) factory_ref: Rc<RefCell<Option<AppRoutingFactory>>>, pub(crate) factory_ref: Rc<RefCell<Option<AppRoutingFactory>>>,
pub(crate) external: RefCell<Vec<ResourceDef>>, pub(crate) external: RefCell<Vec<ResourceDef>>,
@ -142,9 +143,9 @@ where
endpoint_fut: T::Future, endpoint_fut: T::Future,
rmap: Rc<ResourceMap>, rmap: Rc<ResourceMap>,
config: AppConfig, config: AppConfig,
data: Rc<Vec<Box<DataFactory>>>, data: Rc<Vec<Box<dyn DataFactory>>>,
data_factories: Vec<Box<DataFactory>>, data_factories: Vec<Box<dyn DataFactory>>,
data_factories_fut: Vec<Box<dyn Future<Item = Box<DataFactory>, Error = ()>>>, data_factories_fut: Vec<Box<dyn Future<Item = Box<dyn DataFactory>, Error = ()>>>,
_t: PhantomData<B>, _t: PhantomData<B>,
} }

View File

@ -16,7 +16,7 @@ use crate::service::{
ServiceResponse, ServiceResponse,
}; };
type Guards = Vec<Box<Guard>>; type Guards = Vec<Box<dyn Guard>>;
type HttpNewService = type HttpNewService =
boxed::BoxedNewService<(), ServiceRequest, ServiceResponse, Error, ()>; boxed::BoxedNewService<(), ServiceRequest, ServiceResponse, Error, ()>;
@ -31,7 +31,7 @@ pub struct AppService {
Option<Guards>, Option<Guards>,
Option<Rc<ResourceMap>>, Option<Rc<ResourceMap>>,
)>, )>,
service_data: Rc<Vec<Box<DataFactory>>>, service_data: Rc<Vec<Box<dyn DataFactory>>>,
} }
impl AppService { impl AppService {
@ -39,7 +39,7 @@ impl AppService {
pub(crate) fn new( pub(crate) fn new(
config: AppConfig, config: AppConfig,
default: Rc<HttpNewService>, default: Rc<HttpNewService>,
service_data: Rc<Vec<Box<DataFactory>>>, service_data: Rc<Vec<Box<dyn DataFactory>>>,
) -> Self { ) -> Self {
AppService { AppService {
config, config,
@ -101,7 +101,7 @@ impl AppService {
pub fn register_service<F, S>( pub fn register_service<F, S>(
&mut self, &mut self,
rdef: ResourceDef, rdef: ResourceDef,
guards: Option<Vec<Box<Guard>>>, guards: Option<Vec<Box<dyn Guard>>>,
service: F, service: F,
nested: Option<Rc<ResourceMap>>, nested: Option<Rc<ResourceMap>>,
) where ) where
@ -174,8 +174,8 @@ impl Default for AppConfigInner {
/// to set of external methods. This could help with /// to set of external methods. This could help with
/// modularization of big application configuration. /// modularization of big application configuration.
pub struct ServiceConfig { pub struct ServiceConfig {
pub(crate) services: Vec<Box<ServiceFactory>>, pub(crate) services: Vec<Box<dyn ServiceFactory>>,
pub(crate) data: Vec<Box<DataFactory>>, pub(crate) data: Vec<Box<dyn DataFactory>>,
pub(crate) external: Vec<ResourceDef>, pub(crate) external: Vec<ResourceDef>,
} }

View File

@ -100,7 +100,7 @@ pub fn Any<F: Guard + 'static>(guard: F) -> AnyGuard {
} }
/// Matches if any of supplied guards matche. /// Matches if any of supplied guards matche.
pub struct AnyGuard(Vec<Box<Guard>>); pub struct AnyGuard(Vec<Box<dyn Guard>>);
impl AnyGuard { impl AnyGuard {
/// Add guard to a list of guards to check /// Add guard to a list of guards to check
@ -140,7 +140,7 @@ pub fn All<F: Guard + 'static>(guard: F) -> AllGuard {
} }
/// Matches if all of supplied guards. /// Matches if all of supplied guards.
pub struct AllGuard(Vec<Box<Guard>>); pub struct AllGuard(Vec<Box<dyn Guard>>);
impl AllGuard { impl AllGuard {
/// Add new guard to the list of guards to check /// Add new guard to the list of guards to check
@ -167,7 +167,7 @@ pub fn Not<F: Guard + 'static>(guard: F) -> NotGuard {
} }
#[doc(hidden)] #[doc(hidden)]
pub struct NotGuard(Box<Guard>); pub struct NotGuard(Box<dyn Guard>);
impl Guard for NotGuard { impl Guard for NotGuard {
fn check(&self, request: &RequestHead) -> bool { fn check(&self, request: &RequestHead) -> bool {

View File

@ -18,7 +18,7 @@ pub enum ErrorHandlerResponse<B> {
Future(Box<dyn Future<Item = ServiceResponse<B>, Error = Error>>), Future(Box<dyn Future<Item = ServiceResponse<B>, Error = Error>>),
} }
type ErrorHandler<B> = Fn(ServiceResponse<B>) -> Result<ErrorHandlerResponse<B>>; type ErrorHandler<B> = dyn Fn(ServiceResponse<B>) -> Result<ErrorHandlerResponse<B>>;
/// `Middleware` for allowing custom handlers for responses. /// `Middleware` for allowing custom handlers for responses.
/// ///

View File

@ -444,7 +444,9 @@ impl FormatText {
} }
} }
pub(crate) struct FormatDisplay<'a>(&'a Fn(&mut Formatter) -> Result<(), fmt::Error>); pub(crate) struct FormatDisplay<'a>(
&'a dyn Fn(&mut Formatter) -> Result<(), fmt::Error>,
);
impl<'a> fmt::Display for FormatDisplay<'a> { impl<'a> fmt::Display for FormatDisplay<'a> {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), fmt::Error> { fn fmt(&self, fmt: &mut Formatter) -> Result<(), fmt::Error> {

View File

@ -50,7 +50,7 @@ pub struct Resource<T = ResourceEndpoint> {
name: Option<String>, name: Option<String>,
routes: Vec<Route>, routes: Vec<Route>,
data: Option<Extensions>, data: Option<Extensions>,
guards: Vec<Box<Guard>>, guards: Vec<Box<dyn Guard>>,
default: Rc<RefCell<Option<Rc<HttpNewService>>>>, default: Rc<RefCell<Option<Rc<HttpNewService>>>>,
factory_ref: Rc<RefCell<Option<ResourceFactory>>>, factory_ref: Rc<RefCell<Option<ResourceFactory>>>,
} }
@ -118,7 +118,7 @@ where
self self
} }
pub(crate) fn add_guards(mut self, guards: Vec<Box<Guard>>) -> Self { pub(crate) fn add_guards(mut self, guards: Vec<Box<dyn Guard>>) -> Self {
self.guards.extend(guards); self.guards.extend(guards);
self self
} }

View File

@ -13,7 +13,7 @@ use crate::service::{ServiceRequest, ServiceResponse};
use crate::HttpResponse; use crate::HttpResponse;
type BoxedRouteService<Req, Res> = Box< type BoxedRouteService<Req, Res> = Box<
Service< dyn Service<
Request = Req, Request = Req,
Response = Res, Response = Res,
Error = Error, Error = Error,
@ -25,7 +25,7 @@ type BoxedRouteService<Req, Res> = Box<
>; >;
type BoxedRouteNewService<Req, Res> = Box< type BoxedRouteNewService<Req, Res> = Box<
NewService< dyn NewService<
Config = (), Config = (),
Request = Req, Request = Req,
Response = Res, Response = Res,
@ -42,7 +42,7 @@ type BoxedRouteNewService<Req, Res> = Box<
/// If handler is not explicitly set, default *404 Not Found* handler is used. /// If handler is not explicitly set, default *404 Not Found* handler is used.
pub struct Route { pub struct Route {
service: BoxedRouteNewService<ServiceRequest, ServiceResponse>, service: BoxedRouteNewService<ServiceRequest, ServiceResponse>,
guards: Rc<Vec<Box<Guard>>>, guards: Rc<Vec<Box<dyn Guard>>>,
} }
impl Route { impl Route {
@ -56,7 +56,7 @@ impl Route {
} }
} }
pub(crate) fn take_guards(&mut self) -> Vec<Box<Guard>> { pub(crate) fn take_guards(&mut self) -> Vec<Box<dyn Guard>> {
std::mem::replace(Rc::get_mut(&mut self.guards).unwrap(), Vec::new()) std::mem::replace(Rc::get_mut(&mut self.guards).unwrap(), Vec::new())
} }
} }
@ -84,7 +84,7 @@ type RouteFuture = Box<
pub struct CreateRouteService { pub struct CreateRouteService {
fut: RouteFuture, fut: RouteFuture,
guards: Rc<Vec<Box<Guard>>>, guards: Rc<Vec<Box<dyn Guard>>>,
} }
impl Future for CreateRouteService { impl Future for CreateRouteService {
@ -104,7 +104,7 @@ impl Future for CreateRouteService {
pub struct RouteService { pub struct RouteService {
service: BoxedRouteService<ServiceRequest, ServiceResponse>, service: BoxedRouteService<ServiceRequest, ServiceResponse>,
guards: Rc<Vec<Box<Guard>>>, guards: Rc<Vec<Box<dyn Guard>>>,
} }
impl RouteService { impl RouteService {

View File

@ -23,7 +23,7 @@ use crate::service::{
ServiceFactory, ServiceFactoryWrapper, ServiceRequest, ServiceResponse, ServiceFactory, ServiceFactoryWrapper, ServiceRequest, ServiceResponse,
}; };
type Guards = Vec<Box<Guard>>; type Guards = Vec<Box<dyn Guard>>;
type HttpService = BoxedService<ServiceRequest, ServiceResponse, Error>; type HttpService = BoxedService<ServiceRequest, ServiceResponse, Error>;
type HttpNewService = BoxedNewService<(), ServiceRequest, ServiceResponse, Error, ()>; type HttpNewService = BoxedNewService<(), ServiceRequest, ServiceResponse, Error, ()>;
type BoxedResponse = Either< type BoxedResponse = Either<
@ -64,8 +64,8 @@ pub struct Scope<T = ScopeEndpoint> {
endpoint: T, endpoint: T,
rdef: String, rdef: String,
data: Option<Extensions>, data: Option<Extensions>,
services: Vec<Box<ServiceFactory>>, services: Vec<Box<dyn ServiceFactory>>,
guards: Vec<Box<Guard>>, guards: Vec<Box<dyn Guard>>,
default: Rc<RefCell<Option<Rc<HttpNewService>>>>, default: Rc<RefCell<Option<Rc<HttpNewService>>>>,
external: Vec<ResourceDef>, external: Vec<ResourceDef>,
factory_ref: Rc<RefCell<Option<ScopeFactory>>>, factory_ref: Rc<RefCell<Option<ScopeFactory>>>,
@ -578,7 +578,7 @@ impl Future for ScopeFactoryResponse {
pub struct ScopeService { pub struct ScopeService {
data: Option<Rc<Extensions>>, data: Option<Rc<Extensions>>,
router: Router<HttpService, Vec<Box<Guard>>>, router: Router<HttpService, Vec<Box<dyn Guard>>>,
default: Option<HttpService>, default: Option<HttpService>,
_ready: Option<(ServiceRequest, ResourceInfo)>, _ready: Option<(ServiceRequest, ResourceInfo)>,
} }

View File

@ -407,7 +407,7 @@ impl<B: MessageBody> fmt::Debug for ServiceResponse<B> {
pub struct WebService { pub struct WebService {
rdef: String, rdef: String,
name: Option<String>, name: Option<String>,
guards: Vec<Box<Guard>>, guards: Vec<Box<dyn Guard>>,
} }
impl WebService { impl WebService {
@ -476,7 +476,7 @@ struct WebServiceImpl<T> {
srv: T, srv: T,
rdef: String, rdef: String,
name: Option<String>, name: Option<String>,
guards: Vec<Box<Guard>>, guards: Vec<Box<dyn Guard>>,
} }
impl<T> HttpServiceFactory for WebServiceImpl<T> impl<T> HttpServiceFactory for WebServiceImpl<T>

View File

@ -141,7 +141,7 @@ impl<T: fmt::Display> fmt::Display for Form<T> {
#[derive(Clone)] #[derive(Clone)]
pub struct FormConfig { pub struct FormConfig {
limit: usize, limit: usize,
ehandler: Option<Rc<Fn(UrlencodedError, &HttpRequest) -> Error>>, ehandler: Option<Rc<dyn Fn(UrlencodedError, &HttpRequest) -> Error>>,
} }
impl FormConfig { impl FormConfig {

View File

@ -224,7 +224,7 @@ where
/// ``` /// ```
#[derive(Clone)] #[derive(Clone)]
pub struct PathConfig { pub struct PathConfig {
ehandler: Option<Arc<Fn(PathError, &HttpRequest) -> Error + Send + Sync>>, ehandler: Option<Arc<dyn Fn(PathError, &HttpRequest) -> Error + Send + Sync>>,
} }
impl PathConfig { impl PathConfig {

View File

@ -128,7 +128,7 @@ impl FromRequest for Bytes {
#[inline] #[inline]
fn from_request(req: &HttpRequest, payload: &mut dev::Payload) -> Self::Future { fn from_request(req: &HttpRequest, payload: &mut dev::Payload) -> Self::Future {
let mut tmp; let tmp;
let cfg = if let Some(cfg) = req.app_data::<PayloadConfig>() { let cfg = if let Some(cfg) = req.app_data::<PayloadConfig>() {
cfg cfg
} else { } else {
@ -184,7 +184,7 @@ impl FromRequest for String {
#[inline] #[inline]
fn from_request(req: &HttpRequest, payload: &mut dev::Payload) -> Self::Future { fn from_request(req: &HttpRequest, payload: &mut dev::Payload) -> Self::Future {
let mut tmp; let tmp;
let cfg = if let Some(cfg) = req.app_data::<PayloadConfig>() { let cfg = if let Some(cfg) = req.app_data::<PayloadConfig>() {
cfg cfg
} else { } else {

View File

@ -192,7 +192,8 @@ where
/// ``` /// ```
#[derive(Clone)] #[derive(Clone)]
pub struct QueryConfig { pub struct QueryConfig {
ehandler: Option<Arc<Fn(QueryPayloadError, &HttpRequest) -> Error + Send + Sync>>, ehandler:
Option<Arc<dyn Fn(QueryPayloadError, &HttpRequest) -> Error + Send + Sync>>,
} }
impl QueryConfig { impl QueryConfig {