1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-27 18:02:58 +01:00

change generics order for Transform trait

This commit is contained in:
Nikolay Kim 2019-03-05 09:49:08 -08:00
parent aa2967c653
commit 1153715149
9 changed files with 37 additions and 40 deletions

View File

@ -21,7 +21,7 @@ impl<T, A, B, BR> AndThenTransform<T, A, B, BR> {
where
A: NewService<AR, C>,
B: NewService<BR, C, InitError = A::InitError>,
T: Transform<A::Response, B::Service, InitError = A::InitError>,
T: Transform<B::Service, A::Response, InitError = A::InitError>,
T::Error: From<A::Error>,
{
Self {
@ -52,7 +52,7 @@ impl<T, A, B, AR, BR, C> NewService<AR, C> for AndThenTransform<T, A, B, BR>
where
A: NewService<AR, C>,
B: NewService<BR, C, InitError = A::InitError>,
T: Transform<A::Response, B::Service, InitError = A::InitError>,
T: Transform<B::Service, A::Response, InitError = A::InitError>,
T::Error: From<A::Error>,
{
type Response = T::Response;
@ -78,7 +78,7 @@ pub struct AndThenTransformFuture<T, A, B, AR, BR, C>
where
A: NewService<AR, C>,
B: NewService<BR, C, InitError = A::InitError>,
T: Transform<A::Response, B::Service, InitError = A::InitError>,
T: Transform<B::Service, A::Response, InitError = A::InitError>,
T::Error: From<A::Error>,
{
fut_a: A::Future,
@ -93,7 +93,7 @@ impl<T, A, B, AR, BR, C> Future for AndThenTransformFuture<T, A, B, AR, BR, C>
where
A: NewService<AR, C>,
B: NewService<BR, C, InitError = A::InitError>,
T: Transform<A::Response, B::Service, InitError = A::InitError>,
T: Transform<B::Service, A::Response, InitError = A::InitError>,
T::Error: From<A::Error>,
{
type Item = AndThen<FromErr<A::Service, T::Error>, T::Transform>;

View File

@ -277,16 +277,13 @@ where
#[cfg(test)]
mod tests {
use futures::Future;
use super::*;
use crate::{IntoService, NewService, Service, ServiceExt};
use crate::{IntoService, Service, ServiceExt};
#[test]
fn test_fn_service() {
let mut rt = actix_rt::Runtime::new().unwrap();
let srv = (|t: &str| -> Result<usize, ()> { Ok(1) }).into_service();
let srv = (|_t: &str| -> Result<usize, ()> { Ok(1) }).into_service();
let mut srv = srv.and_then(|test: usize| Ok(test));
let s = "HELLO".to_owned();

View File

@ -24,7 +24,7 @@ where
}
}
impl<F, S, R, In, Out, Err> Transform<In, S> for FnTransform<F, S, R, In, Out, Err>
impl<F, S, R, In, Out, Err> Transform<S, In> for FnTransform<F, S, R, In, Out, Err>
where
S: Service<R>,
F: FnMut(In, &mut S) -> Out + Clone,
@ -42,7 +42,7 @@ where
}
}
impl<F, S, R, In, Out, Err> IntoTransform<FnTransform<F, S, R, In, Out, Err>, In, S> for F
impl<F, S, R, In, Out, Err> IntoTransform<FnTransform<F, S, R, In, Out, Err>, S, In> for F
where
S: Service<R>,
F: FnMut(In, &mut S) -> Out + Clone,

View File

@ -210,9 +210,9 @@ pub trait NewService<Request, Config = ()> {
) -> AndThenTransform<T, Self, B, Req>
where
Self: Sized,
T: Transform<Self::Response, B::Service, InitError = Self::InitError>,
T: Transform<B::Service, Self::Response, InitError = Self::InitError>,
T::Error: From<Self::Error>,
T1: IntoTransform<T, Self::Response, B::Service>,
T1: IntoTransform<T, B::Service, Self::Response>,
B: NewService<Req, Config, InitError = Self::InitError>,
B1: IntoNewService<B, Req, Config>,
{

View File

@ -12,7 +12,7 @@ use crate::{NewService, Service};
///
/// * `S` is a wrapped service.
/// * `R` requests handled by this transform service.
pub trait Transform<R, S> {
pub trait Transform<S, R> {
/// Responses given by the service.
type Response;
@ -42,9 +42,9 @@ pub trait Transform<R, S> {
}
}
impl<T, R, S> Transform<R, S> for Rc<T>
impl<T, S, R> Transform<S, R> for Rc<T>
where
T: Transform<R, S>,
T: Transform<S, R>,
{
type Response = T::Response;
type Error = T::Error;
@ -57,9 +57,9 @@ where
}
}
impl<T, R, S> Transform<R, S> for Arc<T>
impl<T, S, R> Transform<S, R> for Arc<T>
where
T: Transform<R, S>,
T: Transform<S, R>,
{
type Response = T::Response;
type Error = T::Error;
@ -73,9 +73,9 @@ where
}
/// Trait for types that can be converted to a *transform service*
pub trait IntoTransform<T, R, S>
pub trait IntoTransform<T, S, R>
where
T: Transform<R, S>,
T: Transform<S, R>,
{
/// Convert to a `TransformService`
fn into_transform(self) -> T;
@ -92,19 +92,19 @@ where
/// `Apply` transform new service
#[derive(Clone)]
pub struct ApplyTransform<T, R, S, Req, Cfg> {
pub struct ApplyTransform<T, S, R, Req, Cfg> {
a: S,
t: Rc<T>,
_t: std::marker::PhantomData<(R, Req, Cfg)>,
}
impl<T, R, S, Req, Cfg> ApplyTransform<T, R, S, Req, Cfg>
impl<T, S, R, Req, Cfg> ApplyTransform<T, S, R, Req, Cfg>
where
S: NewService<Req, Cfg>,
T: Transform<R, S::Service, Error = S::Error, InitError = S::InitError>,
T: Transform<S::Service, R, Error = S::Error, InitError = S::InitError>,
{
/// Create new `ApplyNewService` new service instance
pub fn new<F: IntoTransform<T, R, S::Service>>(t: F, a: S) -> Self {
pub fn new<F: IntoTransform<T, S::Service, R>>(t: F, a: S) -> Self {
Self {
a,
t: Rc::new(t.into_transform()),
@ -113,17 +113,17 @@ where
}
}
impl<T, R, S, Req, Cfg> NewService<R, Cfg> for ApplyTransform<T, R, S, Req, Cfg>
impl<T, S, R, Req, Cfg> NewService<R, Cfg> for ApplyTransform<T, S, R, Req, Cfg>
where
S: NewService<Req, Cfg>,
T: Transform<R, S::Service, Error = S::Error, InitError = S::InitError>,
T: Transform<S::Service, R, Error = S::Error, InitError = S::InitError>,
{
type Response = T::Response;
type Error = T::Error;
type Service = T::Transform;
type InitError = T::InitError;
type Future = ApplyTransformFuture<T, R, S, Req, Cfg>;
type Future = ApplyTransformFuture<T, S, R, Req, Cfg>;
fn new_service(&self, cfg: &Cfg) -> Self::Future {
ApplyTransformFuture {
@ -134,20 +134,20 @@ where
}
}
pub struct ApplyTransformFuture<T, R, S, Req, Cfg>
pub struct ApplyTransformFuture<T, S, R, Req, Cfg>
where
S: NewService<Req, Cfg>,
T: Transform<R, S::Service, Error = S::Error, InitError = S::InitError>,
T: Transform<S::Service, R, Error = S::Error, InitError = S::InitError>,
{
fut_a: S::Future,
fut_t: Option<T::Future>,
t_cell: Rc<T>,
}
impl<T, R, S, Req, Cfg> Future for ApplyTransformFuture<T, R, S, Req, Cfg>
impl<T, S, R, Req, Cfg> Future for ApplyTransformFuture<T, S, R, Req, Cfg>
where
S: NewService<Req, Cfg>,
T: Transform<R, S::Service, Error = S::Error, InitError = S::InitError>,
T: Transform<S::Service, R, Error = S::Error, InitError = S::InitError>,
{
type Item = T::Transform;
type Error = T::InitError;

View File

@ -18,7 +18,7 @@ impl<T, S, F, E> TransformMapInitErr<T, S, F, E> {
/// Create new `MapInitErr` new transform instance
pub fn new<R>(t: T, f: F) -> Self
where
T: Transform<R, S>,
T: Transform<S, R>,
F: Fn(T::InitError) -> E,
{
Self {
@ -43,9 +43,9 @@ where
}
}
impl<T, R, S, F, E> Transform<R, S> for TransformMapInitErr<T, S, F, E>
impl<T, R, S, F, E> Transform<S, R> for TransformMapInitErr<T, S, F, E>
where
T: Transform<R, S>,
T: Transform<S, R>,
F: Fn(T::InitError) -> E + Clone,
{
type Response = T::Response;
@ -62,7 +62,7 @@ where
pub struct TransformMapInitErrFuture<T, R, S, F, E>
where
T: Transform<R, S>,
T: Transform<S, R>,
F: Fn(T::InitError) -> E,
{
fut: T::Future,
@ -71,7 +71,7 @@ where
impl<T, R, S, F, E> TransformMapInitErrFuture<T, R, S, F, E>
where
T: Transform<R, S>,
T: Transform<S, R>,
F: Fn(T::InitError) -> E,
{
fn new(fut: T::Future, f: F) -> Self {
@ -81,7 +81,7 @@ where
impl<T, R, S, F, E> Future for TransformMapInitErrFuture<T, R, S, F, E>
where
T: Transform<R, S>,
T: Transform<S, R>,
F: Fn(T::InitError) -> E + Clone,
{
type Item = T::Transform;

View File

@ -24,7 +24,7 @@ impl Default for InFlight {
}
}
impl<S: Service<R>, R> Transform<R, S> for InFlight {
impl<S: Service<R>, R> Transform<S, R> for InFlight {
type Response = S::Response;
type Error = S::Error;
type InitError = Void;

View File

@ -74,7 +74,7 @@ impl<S> InOrder<S> {
}
}
impl<S, R> Transform<R, S> for InOrder<S>
impl<S, R> Transform<S, R> for InOrder<S>
where
S: Service<R>,
S::Response: 'static,

View File

@ -80,7 +80,7 @@ impl<E> Clone for Timeout<E> {
}
}
impl<S, R, E> Transform<R, S> for Timeout<E>
impl<S, R, E> Transform<S, R> for Timeout<E>
where
S: Service<R>,
{