mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-27 09:42:57 +01:00
nightly clippy warnings
This commit is contained in:
parent
4092c7f326
commit
2a2d7f5768
@ -75,7 +75,7 @@ actix-utils = "0.4.4"
|
||||
actix-router = "0.1.5"
|
||||
actix-rt = "0.2.4"
|
||||
actix-web-codegen = "0.1.2"
|
||||
actix-http = "0.2.5"
|
||||
actix-http = "0.2.6"
|
||||
actix-server = "0.5.1"
|
||||
actix-server-config = "0.1.1"
|
||||
actix-threadpool = "0.1.1"
|
||||
@ -89,7 +89,7 @@ hashbrown = "0.5.0"
|
||||
log = "0.4"
|
||||
mime = "0.3"
|
||||
net2 = "0.2.33"
|
||||
parking_lot = "0.8"
|
||||
parking_lot = "0.9"
|
||||
regex = "1.0"
|
||||
serde = { version = "1.0", features=["derive"] }
|
||||
serde_json = "1.0"
|
||||
|
@ -587,10 +587,10 @@ impl Inner {
|
||||
}
|
||||
Err(CorsError::BadOrigin)
|
||||
} else {
|
||||
return match self.origins {
|
||||
match self.origins {
|
||||
AllOrSome::All => Ok(()),
|
||||
_ => Err(CorsError::MissingOrigin),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -665,7 +665,7 @@ impl Inner {
|
||||
}
|
||||
Err(CorsError::BadRequestHeaders)
|
||||
} else {
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ impl Stream for ChunkedReadFile {
|
||||
}
|
||||
|
||||
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.
|
||||
#[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
|
||||
///
|
||||
@ -475,7 +475,7 @@ impl Service for FilesService {
|
||||
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 {
|
||||
let dir = Directory::new(self.directory.clone(), path);
|
||||
@ -483,7 +483,7 @@ impl Service for FilesService {
|
||||
let x = (self.renderer)(&dir, &req);
|
||||
match x {
|
||||
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 {
|
||||
Either::A(ok(ServiceResponse::from_err(
|
||||
@ -857,7 +857,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
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(
|
||||
App::new().service(Files::new("test", ".").index_file("tests/test.binary")),
|
||||
@ -868,7 +868,7 @@ mod tests {
|
||||
.uri("/t%65st/tests/test.binary")
|
||||
.header(header::RANGE, "bytes=10-20")
|
||||
.to_request();
|
||||
let response = test::call_service(&mut srv, request);
|
||||
let _response = test::call_service(&mut srv, request);
|
||||
|
||||
// let contentlength = response
|
||||
// .headers()
|
||||
@ -891,7 +891,7 @@ mod tests {
|
||||
.uri("/t%65st/tests/test.binary")
|
||||
// .no_default_headers()
|
||||
.to_request();
|
||||
let response = test::call_service(&mut srv, request);
|
||||
let _response = test::call_service(&mut srv, request);
|
||||
|
||||
// let contentlength = response
|
||||
// .headers()
|
||||
@ -939,7 +939,7 @@ mod tests {
|
||||
.method(Method::HEAD)
|
||||
.uri("/t%65st/tests/test.binary")
|
||||
.to_request();
|
||||
let response = test::call_service(&mut srv, request);
|
||||
let _response = test::call_service(&mut srv, request);
|
||||
|
||||
// TODO: fix check
|
||||
// let contentlength = response
|
||||
|
@ -5,7 +5,7 @@ pub struct HttpRange {
|
||||
pub length: u64,
|
||||
}
|
||||
|
||||
static PREFIX: &'static str = "bytes=";
|
||||
static PREFIX: &str = "bytes=";
|
||||
const PREFIX_LEN: usize = 6;
|
||||
|
||||
impl HttpRange {
|
||||
|
@ -3,7 +3,7 @@ use actix_service::{NewService, Service};
|
||||
use futures::{Future, Poll};
|
||||
|
||||
pub(crate) type BoxedHttpService<Req> = Box<
|
||||
Service<
|
||||
dyn Service<
|
||||
Request = Req,
|
||||
Response = (),
|
||||
Error = Error,
|
||||
@ -12,7 +12,7 @@ pub(crate) type BoxedHttpService<Req> = Box<
|
||||
>;
|
||||
|
||||
pub(crate) type BoxedHttpNewService<Req> = Box<
|
||||
NewService<
|
||||
dyn NewService<
|
||||
Config = (),
|
||||
Request = Req,
|
||||
Response = (),
|
||||
|
@ -26,7 +26,7 @@ pub struct HttpServiceBuilder<T, S, X = ExpectHandler, U = UpgradeHandler<T>> {
|
||||
client_disconnect: u64,
|
||||
expect: X,
|
||||
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)>,
|
||||
}
|
||||
|
||||
|
@ -130,7 +130,7 @@ where
|
||||
|
||||
type TunnelFuture = Either<
|
||||
Box<
|
||||
Future<
|
||||
dyn Future<
|
||||
Item = (ResponseHead, Framed<Self::Io, ClientCodec>),
|
||||
Error = SendRequestError,
|
||||
>,
|
||||
@ -192,7 +192,7 @@ where
|
||||
}
|
||||
|
||||
type TunnelFuture = Box<
|
||||
Future<
|
||||
dyn Future<
|
||||
Item = (ResponseHead, Framed<Self::Io, ClientCodec>),
|
||||
Error = SendRequestError,
|
||||
>,
|
||||
|
@ -6,7 +6,7 @@ use ring::rand::{SecureRandom, SystemRandom};
|
||||
use super::private::KEY_LEN as PRIVATE_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";
|
||||
|
||||
/// A cryptographic master key for use with `Signed` and/or `Private` jars.
|
||||
|
@ -10,7 +10,7 @@ use crate::cookie::{Cookie, CookieJar};
|
||||
|
||||
// Keep these in sync, and keep the key len synced with the `private` docs as
|
||||
// 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;
|
||||
pub const KEY_LEN: usize = 32;
|
||||
|
||||
|
@ -6,7 +6,7 @@ use crate::cookie::{Cookie, CookieJar};
|
||||
|
||||
// Keep these in sync, and keep the key len synced with the `signed` docs as
|
||||
// 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;
|
||||
pub const KEY_LEN: usize = 32;
|
||||
|
||||
|
@ -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
|
||||
/// `ResponseError` reference from it.
|
||||
pub struct Error {
|
||||
cause: Box<ResponseError>,
|
||||
cause: Box<dyn ResponseError>,
|
||||
}
|
||||
|
||||
impl Error {
|
||||
/// 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()
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ use hashbrown::HashMap;
|
||||
#[derive(Default)]
|
||||
/// A type map of request extensions.
|
||||
pub struct Extensions {
|
||||
map: HashMap<TypeId, Box<Any>>,
|
||||
map: HashMap<TypeId, Box<dyn Any>>,
|
||||
}
|
||||
|
||||
impl Extensions {
|
||||
@ -35,14 +35,14 @@ impl Extensions {
|
||||
pub fn get<T: 'static>(&self) -> Option<&T> {
|
||||
self.map
|
||||
.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`.
|
||||
pub fn get_mut<T: 'static>(&mut self) -> Option<&mut T> {
|
||||
self.map
|
||||
.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`.
|
||||
@ -50,7 +50,7 @@ impl Extensions {
|
||||
/// If a extension of this type existed, it will be returned.
|
||||
pub fn remove<T: 'static>(&mut self) -> Option<T> {
|
||||
self.map.remove(&TypeId::of::<T>()).and_then(|boxed| {
|
||||
(boxed as Box<Any + 'static>)
|
||||
(boxed as Box<dyn Any + 'static>)
|
||||
.downcast()
|
||||
.ok()
|
||||
.map(|boxed| *boxed)
|
||||
|
@ -502,15 +502,15 @@ impl ChunkedState {
|
||||
fn read_size(rdr: &mut BytesMut, size: &mut u64) -> Poll<ChunkedState, io::Error> {
|
||||
let radix = 16;
|
||||
match byte!(rdr) {
|
||||
b @ b'0'...b'9' => {
|
||||
b @ b'0'..=b'9' => {
|
||||
*size *= radix;
|
||||
*size += u64::from(b - b'0');
|
||||
}
|
||||
b @ b'a'...b'f' => {
|
||||
b @ b'a'..=b'f' => {
|
||||
*size *= radix;
|
||||
*size += u64::from(b + 10 - b'a');
|
||||
}
|
||||
b @ b'A'...b'F' => {
|
||||
b @ b'A'..=b'F' => {
|
||||
*size *= radix;
|
||||
*size += u64::from(b + 10 - b'A');
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ pub struct H1Service<T, P, S, B, X = ExpectHandler, U = UpgradeHandler<T>> {
|
||||
cfg: ServiceConfig,
|
||||
expect: X,
|
||||
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)>,
|
||||
}
|
||||
|
||||
@ -108,7 +108,7 @@ where
|
||||
/// Set on connect callback.
|
||||
pub(crate) fn on_connect(
|
||||
mut self,
|
||||
f: Option<Rc<Fn(&T) -> Box<dyn DataFactory>>>,
|
||||
f: Option<Rc<dyn Fn(&T) -> Box<dyn DataFactory>>>,
|
||||
) -> Self {
|
||||
self.on_connect = f;
|
||||
self
|
||||
@ -174,7 +174,7 @@ where
|
||||
fut_upg: Option<U::Future>,
|
||||
expect: Option<X::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>,
|
||||
_t: PhantomData<(T, P, B)>,
|
||||
}
|
||||
@ -233,7 +233,7 @@ pub struct H1ServiceHandler<T, P, S, B, X, U> {
|
||||
srv: CloneableService<S>,
|
||||
expect: CloneableService<X>,
|
||||
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,
|
||||
_t: PhantomData<(T, P, B)>,
|
||||
}
|
||||
@ -254,7 +254,7 @@ where
|
||||
srv: S,
|
||||
expect: X,
|
||||
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 {
|
||||
srv: CloneableService::new(srv),
|
||||
|
@ -27,7 +27,7 @@ use super::dispatcher::Dispatcher;
|
||||
pub struct H2Service<T, P, S, B> {
|
||||
srv: S,
|
||||
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)>,
|
||||
}
|
||||
|
||||
@ -64,7 +64,7 @@ where
|
||||
/// Set on connect callback.
|
||||
pub(crate) fn on_connect(
|
||||
mut self,
|
||||
f: Option<rc::Rc<Fn(&T) -> Box<dyn DataFactory>>>,
|
||||
f: Option<rc::Rc<dyn Fn(&T) -> Box<dyn DataFactory>>>,
|
||||
) -> Self {
|
||||
self.on_connect = f;
|
||||
self
|
||||
@ -102,7 +102,7 @@ where
|
||||
pub struct H2ServiceResponse<T, P, S: NewService, B> {
|
||||
fut: <S::Future as IntoFuture>::Future,
|
||||
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)>,
|
||||
}
|
||||
|
||||
@ -132,7 +132,7 @@ where
|
||||
pub struct H2ServiceHandler<T, P, S, B> {
|
||||
srv: CloneableService<S>,
|
||||
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)>,
|
||||
}
|
||||
|
||||
@ -146,7 +146,7 @@ where
|
||||
{
|
||||
fn new(
|
||||
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,
|
||||
) -> H2ServiceHandler<T, P, S, B> {
|
||||
H2ServiceHandler {
|
||||
|
@ -26,7 +26,7 @@ pub struct HttpService<T, P, S, B, X = h1::ExpectHandler, U = h1::UpgradeHandler
|
||||
cfg: ServiceConfig,
|
||||
expect: X,
|
||||
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)>,
|
||||
}
|
||||
|
||||
@ -140,7 +140,7 @@ where
|
||||
/// Set on connect callback.
|
||||
pub(crate) fn on_connect(
|
||||
mut self,
|
||||
f: Option<rc::Rc<Fn(&T) -> Box<dyn DataFactory>>>,
|
||||
f: Option<rc::Rc<dyn Fn(&T) -> Box<dyn DataFactory>>>,
|
||||
) -> Self {
|
||||
self.on_connect = f;
|
||||
self
|
||||
@ -196,7 +196,7 @@ pub struct HttpServiceResponse<T, P, S: NewService, B, X: NewService, U: NewServ
|
||||
fut_upg: Option<U::Future>,
|
||||
expect: Option<X::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>,
|
||||
_t: PhantomData<(T, P, B)>,
|
||||
}
|
||||
@ -257,7 +257,7 @@ pub struct HttpServiceHandler<T, P, S, B, X, U> {
|
||||
expect: CloneableService<X>,
|
||||
upgrade: Option<CloneableService<U>>,
|
||||
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)>,
|
||||
}
|
||||
|
||||
@ -278,7 +278,7 @@ where
|
||||
srv: S,
|
||||
expect: X,
|
||||
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 {
|
||||
cfg,
|
||||
|
@ -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
|
||||
pub fn hash_key(key: &[u8]) -> String {
|
||||
|
@ -283,7 +283,7 @@ where
|
||||
res.request().extensions_mut().remove::<IdentityItem>();
|
||||
|
||||
if let Some(id) = id {
|
||||
return Either::A(
|
||||
Either::A(
|
||||
backend
|
||||
.to_response(id.id, id.changed, &mut res)
|
||||
.into_future()
|
||||
@ -291,7 +291,7 @@ where
|
||||
Ok(_) => Ok(res),
|
||||
Err(e) => Ok(res.error_response(e)),
|
||||
}),
|
||||
);
|
||||
)
|
||||
} else {
|
||||
Either::B(ok(res))
|
||||
}
|
||||
|
@ -282,7 +282,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
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());
|
||||
assert_eq!(session.0.borrow().status, SessionStatus::Unchanged);
|
||||
session.purge();
|
||||
@ -291,7 +291,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
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());
|
||||
assert_eq!(session.0.borrow().status, SessionStatus::Unchanged);
|
||||
session.renew();
|
||||
|
@ -28,7 +28,7 @@ pub(crate) trait Connect {
|
||||
head: RequestHead,
|
||||
addr: Option<net::SocketAddr>,
|
||||
) -> Box<
|
||||
Future<
|
||||
dyn Future<
|
||||
Item = (ResponseHead, Framed<BoxedSocket, ClientCodec>),
|
||||
Error = SendRequestError,
|
||||
>,
|
||||
@ -69,7 +69,7 @@ where
|
||||
head: RequestHead,
|
||||
addr: Option<net::SocketAddr>,
|
||||
) -> Box<
|
||||
Future<
|
||||
dyn Future<
|
||||
Item = (ResponseHead, Framed<BoxedSocket, ClientCodec>),
|
||||
Error = SendRequestError,
|
||||
>,
|
||||
@ -93,21 +93,21 @@ where
|
||||
}
|
||||
|
||||
trait AsyncSocket {
|
||||
fn as_read(&self) -> &AsyncRead;
|
||||
fn as_read_mut(&mut self) -> &mut AsyncRead;
|
||||
fn as_write(&mut self) -> &mut AsyncWrite;
|
||||
fn as_read(&self) -> &dyn AsyncRead;
|
||||
fn as_read_mut(&mut self) -> &mut dyn AsyncRead;
|
||||
fn as_write(&mut self) -> &mut dyn AsyncWrite;
|
||||
}
|
||||
|
||||
struct Socket<T: AsyncRead + AsyncWrite>(T);
|
||||
|
||||
impl<T: AsyncRead + AsyncWrite> AsyncSocket for Socket<T> {
|
||||
fn as_read(&self) -> &AsyncRead {
|
||||
fn as_read(&self) -> &dyn AsyncRead {
|
||||
&self.0
|
||||
}
|
||||
fn as_read_mut(&mut self) -> &mut AsyncRead {
|
||||
fn as_read_mut(&mut self) -> &mut dyn AsyncRead {
|
||||
&mut self.0
|
||||
}
|
||||
fn as_write(&mut self) -> &mut AsyncWrite {
|
||||
fn as_write(&mut self) -> &mut dyn AsyncWrite {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
@ -23,16 +23,17 @@ use crate::service::{
|
||||
};
|
||||
|
||||
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
|
||||
/// for building application instances.
|
||||
pub struct App<T, B> {
|
||||
endpoint: T,
|
||||
services: Vec<Box<ServiceFactory>>,
|
||||
services: Vec<Box<dyn ServiceFactory>>,
|
||||
default: Option<Rc<HttpNewService>>,
|
||||
factory_ref: Rc<RefCell<Option<AppRoutingFactory>>>,
|
||||
data: Vec<Box<DataFactory>>,
|
||||
data: Vec<Box<dyn DataFactory>>,
|
||||
data_factories: Vec<FnDataFactory>,
|
||||
config: AppConfigInner,
|
||||
external: Vec<ResourceDef>,
|
||||
|
@ -18,14 +18,15 @@ use crate::request::{HttpRequest, HttpRequestPool};
|
||||
use crate::rmap::ResourceMap;
|
||||
use crate::service::{ServiceFactory, ServiceRequest, ServiceResponse};
|
||||
|
||||
type Guards = Vec<Box<Guard>>;
|
||||
type Guards = Vec<Box<dyn Guard>>;
|
||||
type HttpService = BoxedService<ServiceRequest, ServiceResponse, Error>;
|
||||
type HttpNewService = BoxedNewService<(), ServiceRequest, ServiceResponse, Error, ()>;
|
||||
type BoxedResponse = Either<
|
||||
FutureResult<ServiceResponse, 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>`.
|
||||
/// It also executes data factories.
|
||||
@ -40,10 +41,10 @@ where
|
||||
>,
|
||||
{
|
||||
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) 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) factory_ref: Rc<RefCell<Option<AppRoutingFactory>>>,
|
||||
pub(crate) external: RefCell<Vec<ResourceDef>>,
|
||||
@ -142,9 +143,9 @@ where
|
||||
endpoint_fut: T::Future,
|
||||
rmap: Rc<ResourceMap>,
|
||||
config: AppConfig,
|
||||
data: Rc<Vec<Box<DataFactory>>>,
|
||||
data_factories: Vec<Box<DataFactory>>,
|
||||
data_factories_fut: Vec<Box<dyn Future<Item = Box<DataFactory>, Error = ()>>>,
|
||||
data: Rc<Vec<Box<dyn DataFactory>>>,
|
||||
data_factories: Vec<Box<dyn DataFactory>>,
|
||||
data_factories_fut: Vec<Box<dyn Future<Item = Box<dyn DataFactory>, Error = ()>>>,
|
||||
_t: PhantomData<B>,
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ use crate::service::{
|
||||
ServiceResponse,
|
||||
};
|
||||
|
||||
type Guards = Vec<Box<Guard>>;
|
||||
type Guards = Vec<Box<dyn Guard>>;
|
||||
type HttpNewService =
|
||||
boxed::BoxedNewService<(), ServiceRequest, ServiceResponse, Error, ()>;
|
||||
|
||||
@ -31,7 +31,7 @@ pub struct AppService {
|
||||
Option<Guards>,
|
||||
Option<Rc<ResourceMap>>,
|
||||
)>,
|
||||
service_data: Rc<Vec<Box<DataFactory>>>,
|
||||
service_data: Rc<Vec<Box<dyn DataFactory>>>,
|
||||
}
|
||||
|
||||
impl AppService {
|
||||
@ -39,7 +39,7 @@ impl AppService {
|
||||
pub(crate) fn new(
|
||||
config: AppConfig,
|
||||
default: Rc<HttpNewService>,
|
||||
service_data: Rc<Vec<Box<DataFactory>>>,
|
||||
service_data: Rc<Vec<Box<dyn DataFactory>>>,
|
||||
) -> Self {
|
||||
AppService {
|
||||
config,
|
||||
@ -101,7 +101,7 @@ impl AppService {
|
||||
pub fn register_service<F, S>(
|
||||
&mut self,
|
||||
rdef: ResourceDef,
|
||||
guards: Option<Vec<Box<Guard>>>,
|
||||
guards: Option<Vec<Box<dyn Guard>>>,
|
||||
service: F,
|
||||
nested: Option<Rc<ResourceMap>>,
|
||||
) where
|
||||
@ -174,8 +174,8 @@ impl Default for AppConfigInner {
|
||||
/// to set of external methods. This could help with
|
||||
/// modularization of big application configuration.
|
||||
pub struct ServiceConfig {
|
||||
pub(crate) services: Vec<Box<ServiceFactory>>,
|
||||
pub(crate) data: Vec<Box<DataFactory>>,
|
||||
pub(crate) services: Vec<Box<dyn ServiceFactory>>,
|
||||
pub(crate) data: Vec<Box<dyn DataFactory>>,
|
||||
pub(crate) external: Vec<ResourceDef>,
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ pub fn Any<F: Guard + 'static>(guard: F) -> AnyGuard {
|
||||
}
|
||||
|
||||
/// Matches if any of supplied guards matche.
|
||||
pub struct AnyGuard(Vec<Box<Guard>>);
|
||||
pub struct AnyGuard(Vec<Box<dyn Guard>>);
|
||||
|
||||
impl AnyGuard {
|
||||
/// 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.
|
||||
pub struct AllGuard(Vec<Box<Guard>>);
|
||||
pub struct AllGuard(Vec<Box<dyn Guard>>);
|
||||
|
||||
impl AllGuard {
|
||||
/// 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)]
|
||||
pub struct NotGuard(Box<Guard>);
|
||||
pub struct NotGuard(Box<dyn Guard>);
|
||||
|
||||
impl Guard for NotGuard {
|
||||
fn check(&self, request: &RequestHead) -> bool {
|
||||
|
@ -18,7 +18,7 @@ pub enum ErrorHandlerResponse<B> {
|
||||
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.
|
||||
///
|
||||
|
@ -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> {
|
||||
fn fmt(&self, fmt: &mut Formatter) -> Result<(), fmt::Error> {
|
||||
|
@ -50,7 +50,7 @@ pub struct Resource<T = ResourceEndpoint> {
|
||||
name: Option<String>,
|
||||
routes: Vec<Route>,
|
||||
data: Option<Extensions>,
|
||||
guards: Vec<Box<Guard>>,
|
||||
guards: Vec<Box<dyn Guard>>,
|
||||
default: Rc<RefCell<Option<Rc<HttpNewService>>>>,
|
||||
factory_ref: Rc<RefCell<Option<ResourceFactory>>>,
|
||||
}
|
||||
@ -118,7 +118,7 @@ where
|
||||
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
|
||||
}
|
||||
|
12
src/route.rs
12
src/route.rs
@ -13,7 +13,7 @@ use crate::service::{ServiceRequest, ServiceResponse};
|
||||
use crate::HttpResponse;
|
||||
|
||||
type BoxedRouteService<Req, Res> = Box<
|
||||
Service<
|
||||
dyn Service<
|
||||
Request = Req,
|
||||
Response = Res,
|
||||
Error = Error,
|
||||
@ -25,7 +25,7 @@ type BoxedRouteService<Req, Res> = Box<
|
||||
>;
|
||||
|
||||
type BoxedRouteNewService<Req, Res> = Box<
|
||||
NewService<
|
||||
dyn NewService<
|
||||
Config = (),
|
||||
Request = Req,
|
||||
Response = Res,
|
||||
@ -42,7 +42,7 @@ type BoxedRouteNewService<Req, Res> = Box<
|
||||
/// If handler is not explicitly set, default *404 Not Found* handler is used.
|
||||
pub struct Route {
|
||||
service: BoxedRouteNewService<ServiceRequest, ServiceResponse>,
|
||||
guards: Rc<Vec<Box<Guard>>>,
|
||||
guards: Rc<Vec<Box<dyn Guard>>>,
|
||||
}
|
||||
|
||||
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())
|
||||
}
|
||||
}
|
||||
@ -84,7 +84,7 @@ type RouteFuture = Box<
|
||||
|
||||
pub struct CreateRouteService {
|
||||
fut: RouteFuture,
|
||||
guards: Rc<Vec<Box<Guard>>>,
|
||||
guards: Rc<Vec<Box<dyn Guard>>>,
|
||||
}
|
||||
|
||||
impl Future for CreateRouteService {
|
||||
@ -104,7 +104,7 @@ impl Future for CreateRouteService {
|
||||
|
||||
pub struct RouteService {
|
||||
service: BoxedRouteService<ServiceRequest, ServiceResponse>,
|
||||
guards: Rc<Vec<Box<Guard>>>,
|
||||
guards: Rc<Vec<Box<dyn Guard>>>,
|
||||
}
|
||||
|
||||
impl RouteService {
|
||||
|
@ -23,7 +23,7 @@ use crate::service::{
|
||||
ServiceFactory, ServiceFactoryWrapper, ServiceRequest, ServiceResponse,
|
||||
};
|
||||
|
||||
type Guards = Vec<Box<Guard>>;
|
||||
type Guards = Vec<Box<dyn Guard>>;
|
||||
type HttpService = BoxedService<ServiceRequest, ServiceResponse, Error>;
|
||||
type HttpNewService = BoxedNewService<(), ServiceRequest, ServiceResponse, Error, ()>;
|
||||
type BoxedResponse = Either<
|
||||
@ -64,8 +64,8 @@ pub struct Scope<T = ScopeEndpoint> {
|
||||
endpoint: T,
|
||||
rdef: String,
|
||||
data: Option<Extensions>,
|
||||
services: Vec<Box<ServiceFactory>>,
|
||||
guards: Vec<Box<Guard>>,
|
||||
services: Vec<Box<dyn ServiceFactory>>,
|
||||
guards: Vec<Box<dyn Guard>>,
|
||||
default: Rc<RefCell<Option<Rc<HttpNewService>>>>,
|
||||
external: Vec<ResourceDef>,
|
||||
factory_ref: Rc<RefCell<Option<ScopeFactory>>>,
|
||||
@ -578,7 +578,7 @@ impl Future for ScopeFactoryResponse {
|
||||
|
||||
pub struct ScopeService {
|
||||
data: Option<Rc<Extensions>>,
|
||||
router: Router<HttpService, Vec<Box<Guard>>>,
|
||||
router: Router<HttpService, Vec<Box<dyn Guard>>>,
|
||||
default: Option<HttpService>,
|
||||
_ready: Option<(ServiceRequest, ResourceInfo)>,
|
||||
}
|
||||
|
@ -407,7 +407,7 @@ impl<B: MessageBody> fmt::Debug for ServiceResponse<B> {
|
||||
pub struct WebService {
|
||||
rdef: String,
|
||||
name: Option<String>,
|
||||
guards: Vec<Box<Guard>>,
|
||||
guards: Vec<Box<dyn Guard>>,
|
||||
}
|
||||
|
||||
impl WebService {
|
||||
@ -476,7 +476,7 @@ struct WebServiceImpl<T> {
|
||||
srv: T,
|
||||
rdef: String,
|
||||
name: Option<String>,
|
||||
guards: Vec<Box<Guard>>,
|
||||
guards: Vec<Box<dyn Guard>>,
|
||||
}
|
||||
|
||||
impl<T> HttpServiceFactory for WebServiceImpl<T>
|
||||
|
@ -141,7 +141,7 @@ impl<T: fmt::Display> fmt::Display for Form<T> {
|
||||
#[derive(Clone)]
|
||||
pub struct FormConfig {
|
||||
limit: usize,
|
||||
ehandler: Option<Rc<Fn(UrlencodedError, &HttpRequest) -> Error>>,
|
||||
ehandler: Option<Rc<dyn Fn(UrlencodedError, &HttpRequest) -> Error>>,
|
||||
}
|
||||
|
||||
impl FormConfig {
|
||||
|
@ -224,7 +224,7 @@ where
|
||||
/// ```
|
||||
#[derive(Clone)]
|
||||
pub struct PathConfig {
|
||||
ehandler: Option<Arc<Fn(PathError, &HttpRequest) -> Error + Send + Sync>>,
|
||||
ehandler: Option<Arc<dyn Fn(PathError, &HttpRequest) -> Error + Send + Sync>>,
|
||||
}
|
||||
|
||||
impl PathConfig {
|
||||
|
@ -128,7 +128,7 @@ impl FromRequest for Bytes {
|
||||
|
||||
#[inline]
|
||||
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>() {
|
||||
cfg
|
||||
} else {
|
||||
@ -184,7 +184,7 @@ impl FromRequest for String {
|
||||
|
||||
#[inline]
|
||||
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>() {
|
||||
cfg
|
||||
} else {
|
||||
|
@ -192,7 +192,8 @@ where
|
||||
/// ```
|
||||
#[derive(Clone)]
|
||||
pub struct QueryConfig {
|
||||
ehandler: Option<Arc<Fn(QueryPayloadError, &HttpRequest) -> Error + Send + Sync>>,
|
||||
ehandler:
|
||||
Option<Arc<dyn Fn(QueryPayloadError, &HttpRequest) -> Error + Send + Sync>>,
|
||||
}
|
||||
|
||||
impl QueryConfig {
|
||||
|
Loading…
Reference in New Issue
Block a user