From 1153715149af423fee2b3cdf5f0442c82d559265 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Tue, 5 Mar 2019 09:49:08 -0800 Subject: [PATCH] change generics order for Transform trait --- actix-service/src/and_then_apply.rs | 8 ++--- actix-service/src/fn_service.rs | 7 ++-- actix-service/src/fn_transform.rs | 4 +-- actix-service/src/lib.rs | 4 +-- actix-service/src/transform.rs | 36 ++++++++++----------- actix-service/src/transform_map_init_err.rs | 12 +++---- actix-utils/src/inflight.rs | 2 +- actix-utils/src/order.rs | 2 +- actix-utils/src/timeout.rs | 2 +- 9 files changed, 37 insertions(+), 40 deletions(-) diff --git a/actix-service/src/and_then_apply.rs b/actix-service/src/and_then_apply.rs index d24479bc..452f86d1 100644 --- a/actix-service/src/and_then_apply.rs +++ b/actix-service/src/and_then_apply.rs @@ -21,7 +21,7 @@ impl AndThenTransform { where A: NewService, B: NewService, - T: Transform, + T: Transform, T::Error: From, { Self { @@ -52,7 +52,7 @@ impl NewService for AndThenTransform where A: NewService, B: NewService, - T: Transform, + T: Transform, T::Error: From, { type Response = T::Response; @@ -78,7 +78,7 @@ pub struct AndThenTransformFuture where A: NewService, B: NewService, - T: Transform, + T: Transform, T::Error: From, { fut_a: A::Future, @@ -93,7 +93,7 @@ impl Future for AndThenTransformFuture where A: NewService, B: NewService, - T: Transform, + T: Transform, T::Error: From, { type Item = AndThen, T::Transform>; diff --git a/actix-service/src/fn_service.rs b/actix-service/src/fn_service.rs index e32ad120..3d55b333 100644 --- a/actix-service/src/fn_service.rs +++ b/actix-service/src/fn_service.rs @@ -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 { Ok(1) }).into_service(); + let srv = (|_t: &str| -> Result { Ok(1) }).into_service(); let mut srv = srv.and_then(|test: usize| Ok(test)); let s = "HELLO".to_owned(); diff --git a/actix-service/src/fn_transform.rs b/actix-service/src/fn_transform.rs index 24c56d2a..c3737f22 100644 --- a/actix-service/src/fn_transform.rs +++ b/actix-service/src/fn_transform.rs @@ -24,7 +24,7 @@ where } } -impl Transform for FnTransform +impl Transform for FnTransform where S: Service, F: FnMut(In, &mut S) -> Out + Clone, @@ -42,7 +42,7 @@ where } } -impl IntoTransform, In, S> for F +impl IntoTransform, S, In> for F where S: Service, F: FnMut(In, &mut S) -> Out + Clone, diff --git a/actix-service/src/lib.rs b/actix-service/src/lib.rs index ca6f5b95..0bff0813 100644 --- a/actix-service/src/lib.rs +++ b/actix-service/src/lib.rs @@ -210,9 +210,9 @@ pub trait NewService { ) -> AndThenTransform where Self: Sized, - T: Transform, + T: Transform, T::Error: From, - T1: IntoTransform, + T1: IntoTransform, B: NewService, B1: IntoNewService, { diff --git a/actix-service/src/transform.rs b/actix-service/src/transform.rs index 98944183..edba905e 100644 --- a/actix-service/src/transform.rs +++ b/actix-service/src/transform.rs @@ -12,7 +12,7 @@ use crate::{NewService, Service}; /// /// * `S` is a wrapped service. /// * `R` requests handled by this transform service. -pub trait Transform { +pub trait Transform { /// Responses given by the service. type Response; @@ -42,9 +42,9 @@ pub trait Transform { } } -impl Transform for Rc +impl Transform for Rc where - T: Transform, + T: Transform, { type Response = T::Response; type Error = T::Error; @@ -57,9 +57,9 @@ where } } -impl Transform for Arc +impl Transform for Arc where - T: Transform, + T: Transform, { 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 +pub trait IntoTransform where - T: Transform, + T: Transform, { /// Convert to a `TransformService` fn into_transform(self) -> T; @@ -92,19 +92,19 @@ where /// `Apply` transform new service #[derive(Clone)] -pub struct ApplyTransform { +pub struct ApplyTransform { a: S, t: Rc, _t: std::marker::PhantomData<(R, Req, Cfg)>, } -impl ApplyTransform +impl ApplyTransform where S: NewService, - T: Transform, + T: Transform, { /// Create new `ApplyNewService` new service instance - pub fn new>(t: F, a: S) -> Self { + pub fn new>(t: F, a: S) -> Self { Self { a, t: Rc::new(t.into_transform()), @@ -113,17 +113,17 @@ where } } -impl NewService for ApplyTransform +impl NewService for ApplyTransform where S: NewService, - T: Transform, + T: Transform, { type Response = T::Response; type Error = T::Error; type Service = T::Transform; type InitError = T::InitError; - type Future = ApplyTransformFuture; + type Future = ApplyTransformFuture; fn new_service(&self, cfg: &Cfg) -> Self::Future { ApplyTransformFuture { @@ -134,20 +134,20 @@ where } } -pub struct ApplyTransformFuture +pub struct ApplyTransformFuture where S: NewService, - T: Transform, + T: Transform, { fut_a: S::Future, fut_t: Option, t_cell: Rc, } -impl Future for ApplyTransformFuture +impl Future for ApplyTransformFuture where S: NewService, - T: Transform, + T: Transform, { type Item = T::Transform; type Error = T::InitError; diff --git a/actix-service/src/transform_map_init_err.rs b/actix-service/src/transform_map_init_err.rs index 3655b6b3..48589ffc 100644 --- a/actix-service/src/transform_map_init_err.rs +++ b/actix-service/src/transform_map_init_err.rs @@ -18,7 +18,7 @@ impl TransformMapInitErr { /// Create new `MapInitErr` new transform instance pub fn new(t: T, f: F) -> Self where - T: Transform, + T: Transform, F: Fn(T::InitError) -> E, { Self { @@ -43,9 +43,9 @@ where } } -impl Transform for TransformMapInitErr +impl Transform for TransformMapInitErr where - T: Transform, + T: Transform, F: Fn(T::InitError) -> E + Clone, { type Response = T::Response; @@ -62,7 +62,7 @@ where pub struct TransformMapInitErrFuture where - T: Transform, + T: Transform, F: Fn(T::InitError) -> E, { fut: T::Future, @@ -71,7 +71,7 @@ where impl TransformMapInitErrFuture where - T: Transform, + T: Transform, F: Fn(T::InitError) -> E, { fn new(fut: T::Future, f: F) -> Self { @@ -81,7 +81,7 @@ where impl Future for TransformMapInitErrFuture where - T: Transform, + T: Transform, F: Fn(T::InitError) -> E + Clone, { type Item = T::Transform; diff --git a/actix-utils/src/inflight.rs b/actix-utils/src/inflight.rs index 82f425b3..1462e32a 100644 --- a/actix-utils/src/inflight.rs +++ b/actix-utils/src/inflight.rs @@ -24,7 +24,7 @@ impl Default for InFlight { } } -impl, R> Transform for InFlight { +impl, R> Transform for InFlight { type Response = S::Response; type Error = S::Error; type InitError = Void; diff --git a/actix-utils/src/order.rs b/actix-utils/src/order.rs index 288b4e4a..8b0e6b6e 100644 --- a/actix-utils/src/order.rs +++ b/actix-utils/src/order.rs @@ -74,7 +74,7 @@ impl InOrder { } } -impl Transform for InOrder +impl Transform for InOrder where S: Service, S::Response: 'static, diff --git a/actix-utils/src/timeout.rs b/actix-utils/src/timeout.rs index 4493a112..10b90aa5 100644 --- a/actix-utils/src/timeout.rs +++ b/actix-utils/src/timeout.rs @@ -80,7 +80,7 @@ impl Clone for Timeout { } } -impl Transform for Timeout +impl Transform for Timeout where S: Service, {