1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-08-22 05:35:08 +02:00

update middleware impl

This commit is contained in:
Nikolay Kim
2019-03-04 21:37:57 -08:00
parent 2e79562c9d
commit b6fe1dacf2
7 changed files with 102 additions and 103 deletions

View File

@@ -1,8 +1,3 @@
use std::marker::PhantomData;
use actix_service::{NewTransform, Service, Transform};
use futures::future::{ok, FutureResult};
#[cfg(any(feature = "brotli", feature = "flate2"))]
mod compress;
#[cfg(any(feature = "brotli", feature = "flate2"))]
@@ -10,43 +5,3 @@ pub use self::compress::Compress;
mod defaultheaders;
pub use self::defaultheaders::DefaultHeaders;
/// Helper for middleware service factory
pub struct MiddlewareFactory<T, S>
where
T: Transform<S> + Clone,
S: Service,
{
tr: T,
_t: PhantomData<S>,
}
impl<T, S> MiddlewareFactory<T, S>
where
T: Transform<S> + Clone,
S: Service,
{
pub fn new(tr: T) -> Self {
MiddlewareFactory {
tr,
_t: PhantomData,
}
}
}
impl<T, S, C> NewTransform<S, C> for MiddlewareFactory<T, S>
where
T: Transform<S> + Clone,
S: Service,
{
type Request = T::Request;
type Response = T::Response;
type Error = T::Error;
type Transform = T;
type InitError = ();
type Future = FutureResult<Self::Transform, Self::InitError>;
fn new_transform(&self, _: &C) -> Self::Future {
ok(self.tr.clone())
}
}