1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-08-20 06:25:37 +02:00

make service Request type generic

This commit is contained in:
Nikolay Kim
2019-03-05 07:35:26 -08:00
parent e8a49801eb
commit dfbb77f98d
34 changed files with 622 additions and 747 deletions

View File

@@ -5,16 +5,16 @@ use futures::IntoFuture;
use crate::{Apply, IntoTransform, Service, Transform};
pub struct FnTransform<F, S, In, Out, Err>
pub struct FnTransform<F, S, R, In, Out, Err>
where
F: FnMut(In, &mut S) -> Out + Clone,
Out: IntoFuture,
{
f: F,
_t: PhantomData<(S, In, Out, Err)>,
_t: PhantomData<(S, R, In, Out, Err)>,
}
impl<F, S, In, Out, Err> FnTransform<F, S, In, Out, Err>
impl<F, S, R, In, Out, Err> FnTransform<F, S, R, In, Out, Err>
where
F: FnMut(In, &mut S) -> Out + Clone,
Out: IntoFuture,
@@ -24,17 +24,16 @@ where
}
}
impl<F, S, In, Out, Err> Transform<S> for FnTransform<F, S, In, Out, Err>
impl<F, S, R, In, Out, Err> Transform<In, S> for FnTransform<F, S, R, In, Out, Err>
where
S: Service,
S: Service<R>,
F: FnMut(In, &mut S) -> Out + Clone,
Out: IntoFuture,
Out::Error: From<S::Error>,
{
type Request = In;
type Response = Out::Item;
type Error = Out::Error;
type Transform = Apply<S, F, In, Out>;
type Transform = Apply<S, R, F, In, Out>;
type InitError = Err;
type Future = FutureResult<Self::Transform, Self::InitError>;
@@ -43,19 +42,19 @@ where
}
}
impl<F, S, In, Out, Err> IntoTransform<FnTransform<F, S, In, Out, Err>, S> for F
impl<F, S, R, In, Out, Err> IntoTransform<FnTransform<F, S, R, In, Out, Err>, In, S> for F
where
S: Service,
S: Service<R>,
F: FnMut(In, &mut S) -> Out + Clone,
Out: IntoFuture,
Out::Error: From<S::Error>,
{
fn into_transform(self) -> FnTransform<F, S, In, Out, Err> {
fn into_transform(self) -> FnTransform<F, S, R, In, Out, Err> {
FnTransform::new(self)
}
}
impl<F, S, In, Out, Err> Clone for FnTransform<F, S, In, Out, Err>
impl<F, S, R, In, Out, Err> Clone for FnTransform<F, S, R, In, Out, Err>
where
F: FnMut(In, &mut S) -> Out + Clone,
Out: IntoFuture,