diff --git a/actix-service/CHANGES.md b/actix-service/CHANGES.md index 60fd53d7..57f37154 100644 --- a/actix-service/CHANGES.md +++ b/actix-service/CHANGES.md @@ -1,5 +1,14 @@ # Changes +## [0.3.2] - 2019-03-04 + +### Changed + +* Change `NewService::Future` and `Transform::Future` to the `IntoFuture` trait. + +* Export `AndThenTransform` type + + ## [0.3.1] - 2019-03-04 ### Changed diff --git a/actix-service/Cargo.toml b/actix-service/Cargo.toml index ebdc1104..56095859 100644 --- a/actix-service/Cargo.toml +++ b/actix-service/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-service" -version = "0.3.1" +version = "0.3.2" authors = ["Nikolay Kim "] description = "Actix Service" keywords = ["network", "framework", "async", "futures"] diff --git a/actix-service/src/and_then.rs b/actix-service/src/and_then.rs index ee0f5e18..9ef3a4d7 100644 --- a/actix-service/src/and_then.rs +++ b/actix-service/src/and_then.rs @@ -1,6 +1,6 @@ use std::marker::PhantomData; -use futures::{try_ready, Async, Future, Poll}; +use futures::{try_ready, Async, Future, IntoFuture, Poll}; use super::{IntoNewService, NewService, Service}; use crate::cell::Cell; @@ -142,7 +142,10 @@ where type Future = AndThenNewServiceFuture; fn new_service(&self, cfg: &C) -> Self::Future { - AndThenNewServiceFuture::new(self.a.new_service(cfg), self.b.new_service(cfg)) + AndThenNewServiceFuture::new( + self.a.new_service(cfg).into_future(), + self.b.new_service(cfg).into_future(), + ) } } @@ -165,8 +168,8 @@ where A: NewService, B: NewService, { - fut_b: B::Future, - fut_a: A::Future, + fut_b: ::Future, + fut_a: ::Future, a: Option, b: Option, } @@ -176,7 +179,10 @@ where A: NewService, B: NewService, { - fn new(fut_a: A::Future, fut_b: B::Future) -> Self { + fn new( + fut_a: ::Future, + fut_b: ::Future, + ) -> Self { AndThenNewServiceFuture { fut_a, fut_b, diff --git a/actix-service/src/and_then_apply.rs b/actix-service/src/and_then_apply.rs index 70858a9c..83f17917 100644 --- a/actix-service/src/and_then_apply.rs +++ b/actix-service/src/and_then_apply.rs @@ -1,20 +1,20 @@ use std::rc::Rc; -use futures::{Async, Future, Poll}; +use futures::{Async, Future, IntoFuture, Poll}; use crate::and_then::AndThen; use crate::from_err::FromErr; use crate::{NewService, Transform}; /// `Apply` new service combinator -pub struct AndThenTransformNewService { +pub struct AndThenTransform { a: A, b: B, t: Rc, _t: std::marker::PhantomData, } -impl AndThenTransformNewService +impl AndThenTransform where A: NewService, B: NewService, @@ -32,7 +32,7 @@ where } } -impl Clone for AndThenTransformNewService +impl Clone for AndThenTransform where A: Clone, B: Clone, @@ -47,7 +47,7 @@ where } } -impl NewService for AndThenTransformNewService +impl NewService for AndThenTransform where A: NewService, B: NewService, @@ -60,36 +60,36 @@ where type InitError = T::InitError; type Service = AndThen, T::Transform>; - type Future = AndThenTransformNewServiceFuture; + type Future = AndThenTransformFuture; fn new_service(&self, cfg: &C) -> Self::Future { - AndThenTransformNewServiceFuture { + AndThenTransformFuture { a: None, t: None, t_cell: self.t.clone(), - fut_a: self.a.new_service(cfg), - fut_b: self.b.new_service(cfg), + fut_a: self.a.new_service(cfg).into_future(), + fut_b: self.b.new_service(cfg).into_future(), fut_t: None, } } } -pub struct AndThenTransformNewServiceFuture +pub struct AndThenTransformFuture where A: NewService, B: NewService, T: Transform, T::Error: From, { - fut_a: A::Future, - fut_b: B::Future, - fut_t: Option, + fut_a: ::Future, + fut_b: ::Future, + fut_t: Option<::Future>, a: Option, t: Option, t_cell: Rc, } -impl Future for AndThenTransformNewServiceFuture +impl Future for AndThenTransformFuture where A: NewService, B: NewService, @@ -102,7 +102,7 @@ where fn poll(&mut self) -> Poll { if self.fut_t.is_none() { if let Async::Ready(service) = self.fut_b.poll()? { - self.fut_t = Some(self.t_cell.new_transform(service)); + self.fut_t = Some(self.t_cell.new_transform(service).into_future()); } } diff --git a/actix-service/src/and_then_apply_fn.rs b/actix-service/src/and_then_apply_fn.rs index 8969042c..19dbf5ce 100644 --- a/actix-service/src/and_then_apply_fn.rs +++ b/actix-service/src/and_then_apply_fn.rs @@ -195,8 +195,8 @@ where a: None, b: None, f: self.f.clone(), - fut_a: self.a.new_service(cfg), - fut_b: self.b.new_service(cfg), + fut_a: self.a.new_service(cfg).into_future(), + fut_b: self.b.new_service(cfg).into_future(), } } } @@ -209,8 +209,8 @@ where Out: IntoFuture, Out::Error: Into, { - fut_b: B::Future, - fut_a: A::Future, + fut_b: ::Future, + fut_a: ::Future, f: Cell, a: Option, b: Option, diff --git a/actix-service/src/apply.rs b/actix-service/src/apply.rs index d5dda2d4..6700a5bc 100644 --- a/actix-service/src/apply.rs +++ b/actix-service/src/apply.rs @@ -124,7 +124,7 @@ where type Future = ApplyNewServiceFuture; fn new_service(&self, cfg: &Cfg) -> Self::Future { - ApplyNewServiceFuture::new(self.service.new_service(cfg), self.f.clone()) + ApplyNewServiceFuture::new(self.service.new_service(cfg).into_future(), self.f.clone()) } } @@ -134,7 +134,7 @@ where F: FnMut(In, &mut T::Service) -> Out + Clone, Out: IntoFuture, { - fut: T::Future, + fut: ::Future, f: Option, r: PhantomData<(In, Out)>, } @@ -145,7 +145,7 @@ where F: FnMut(In, &mut T::Service) -> Out + Clone, Out: IntoFuture, { - fn new(fut: T::Future, f: F) -> Self { + fn new(fut: ::Future, f: F) -> Self { ApplyNewServiceFuture { f: Some(f), fut, diff --git a/actix-service/src/boxed.rs b/actix-service/src/boxed.rs index e5257327..91c7bbb2 100644 --- a/actix-service/src/boxed.rs +++ b/actix-service/src/boxed.rs @@ -1,5 +1,5 @@ use crate::{NewService, Service}; -use futures::{Future, Poll}; +use futures::{Future, IntoFuture, Poll}; pub type BoxedService = Box< Service< @@ -96,7 +96,12 @@ where type Future = Box>; fn new_service(&self, cfg: &C) -> Self::Future { - Box::new(self.service.new_service(cfg).map(ServiceWrapper::boxed)) + Box::new( + self.service + .new_service(cfg) + .into_future() + .map(ServiceWrapper::boxed), + ) } } diff --git a/actix-service/src/from_err.rs b/actix-service/src/from_err.rs index 31ccb2d9..52477193 100644 --- a/actix-service/src/from_err.rs +++ b/actix-service/src/from_err.rs @@ -1,6 +1,6 @@ use std::marker::PhantomData; -use futures::{Async, Future, Poll}; +use futures::{Async, Future, IntoFuture, Poll}; use super::{NewService, Service}; @@ -124,7 +124,7 @@ where fn new_service(&self, cfg: &C) -> Self::Future { FromErrNewServiceFuture { - fut: self.a.new_service(cfg), + fut: self.a.new_service(cfg).into_future(), e: PhantomData, } } @@ -135,7 +135,7 @@ where A: NewService, E: From, { - fut: A::Future, + fut: ::Future, e: PhantomData, } diff --git a/actix-service/src/lib.rs b/actix-service/src/lib.rs index 03705081..7c14cf0a 100644 --- a/actix-service/src/lib.rs +++ b/actix-service/src/lib.rs @@ -23,7 +23,7 @@ mod transform; mod transform_map_init_err; pub use self::and_then::{AndThen, AndThenNewService}; -use self::and_then_apply::AndThenTransformNewService; +pub use self::and_then_apply::AndThenTransform; use self::and_then_apply_fn::{AndThenApply, AndThenApplyNewService}; pub use self::apply::{Apply, ApplyNewService}; pub use self::fn_service::{fn_cfg_factory, fn_factory, fn_service, FnService}; @@ -199,7 +199,7 @@ pub trait NewService { type InitError; /// The future of the `Service` instance. - type Future: Future; + type Future: IntoFuture; /// Create and return a new service value asynchronously. fn new_service(&self, cfg: &Config) -> Self::Future; @@ -210,7 +210,7 @@ pub trait NewService { self, transform: T1, service: B1, - ) -> AndThenTransformNewService + ) -> AndThenTransform where Self: Sized, T: Transform, @@ -219,11 +219,7 @@ pub trait NewService { B: NewService, B1: IntoNewService, { - AndThenTransformNewService::new( - transform.into_transform(), - self, - service.into_new_service(), - ) + AndThenTransform::new(transform.into_transform(), self, service.into_new_service()) } /// Apply function to specified service and use it as a next service in diff --git a/actix-service/src/map.rs b/actix-service/src/map.rs index a98d14f5..1c35ba4c 100644 --- a/actix-service/src/map.rs +++ b/actix-service/src/map.rs @@ -1,6 +1,6 @@ use std::marker::PhantomData; -use futures::{Async, Future, Poll}; +use futures::{Async, Future, IntoFuture, Poll}; use super::{NewService, Service}; @@ -146,7 +146,7 @@ where type Future = MapNewServiceFuture; fn new_service(&self, cfg: &Cfg) -> Self::Future { - MapNewServiceFuture::new(self.a.new_service(cfg), self.f.clone()) + MapNewServiceFuture::new(self.a.new_service(cfg).into_future(), self.f.clone()) } } @@ -155,7 +155,7 @@ where A: NewService, F: FnMut(A::Response) -> Res, { - fut: A::Future, + fut: ::Future, f: Option, } @@ -164,7 +164,7 @@ where A: NewService, F: FnMut(A::Response) -> Res, { - fn new(fut: A::Future, f: F) -> Self { + fn new(fut: ::Future, f: F) -> Self { MapNewServiceFuture { f: Some(f), fut } } } diff --git a/actix-service/src/map_err.rs b/actix-service/src/map_err.rs index cd15d239..26c12fe8 100644 --- a/actix-service/src/map_err.rs +++ b/actix-service/src/map_err.rs @@ -1,6 +1,6 @@ use std::marker::PhantomData; -use futures::{Async, Future, Poll}; +use futures::{Async, Future, IntoFuture, Poll}; use super::{NewService, Service}; @@ -147,7 +147,7 @@ where type Future = MapErrNewServiceFuture; fn new_service(&self, cfg: &C) -> Self::Future { - MapErrNewServiceFuture::new(self.a.new_service(cfg), self.f.clone()) + MapErrNewServiceFuture::new(self.a.new_service(cfg).into_future(), self.f.clone()) } } @@ -156,7 +156,7 @@ where A: NewService, F: Fn(A::Error) -> E, { - fut: A::Future, + fut: ::Future, f: F, } @@ -165,7 +165,7 @@ where A: NewService, F: Fn(A::Error) -> E, { - fn new(fut: A::Future, f: F) -> Self { + fn new(fut: ::Future, f: F) -> Self { MapErrNewServiceFuture { f, fut } } } diff --git a/actix-service/src/map_init_err.rs b/actix-service/src/map_init_err.rs index 094a4dbe..0cf2ad2e 100644 --- a/actix-service/src/map_init_err.rs +++ b/actix-service/src/map_init_err.rs @@ -1,6 +1,6 @@ use std::marker::PhantomData; -use futures::{Future, Poll}; +use futures::{Future, IntoFuture, Poll}; use super::NewService; @@ -54,7 +54,7 @@ where type Future = MapInitErrFuture; fn new_service(&self, cfg: &C) -> Self::Future { - MapInitErrFuture::new(self.a.new_service(cfg), self.f.clone()) + MapInitErrFuture::new(self.a.new_service(cfg).into_future(), self.f.clone()) } } @@ -64,7 +64,7 @@ where F: Fn(A::InitError) -> E, { f: F, - fut: A::Future, + fut: ::Future, } impl MapInitErrFuture @@ -72,7 +72,7 @@ where A: NewService, F: Fn(A::InitError) -> E, { - fn new(fut: A::Future, f: F) -> Self { + fn new(fut: ::Future, f: F) -> Self { MapInitErrFuture { f, fut } } } diff --git a/actix-service/src/then.rs b/actix-service/src/then.rs index c0a31bfd..1bfc5c79 100644 --- a/actix-service/src/then.rs +++ b/actix-service/src/then.rs @@ -1,6 +1,6 @@ use std::marker::PhantomData; -use futures::{try_ready, Async, Future, Poll}; +use futures::{try_ready, Async, Future, IntoFuture, Poll}; use super::{IntoNewService, NewService, Service}; use crate::cell::Cell; @@ -157,7 +157,10 @@ where type Future = ThenNewServiceFuture; fn new_service(&self, cfg: &C) -> Self::Future { - ThenNewServiceFuture::new(self.a.new_service(cfg), self.b.new_service(cfg)) + ThenNewServiceFuture::new( + self.a.new_service(cfg).into_future(), + self.b.new_service(cfg).into_future(), + ) } } @@ -185,8 +188,8 @@ where InitError = A::InitError, >, { - fut_b: B::Future, - fut_a: A::Future, + fut_b: ::Future, + fut_a: ::Future, a: Option, b: Option, } @@ -201,7 +204,10 @@ where InitError = A::InitError, >, { - fn new(fut_a: A::Future, fut_b: B::Future) -> Self { + fn new( + fut_a: ::Future, + fut_b: ::Future, + ) -> Self { ThenNewServiceFuture { fut_a, fut_b, diff --git a/actix-service/src/transform.rs b/actix-service/src/transform.rs index 4621d09c..7e5ba920 100644 --- a/actix-service/src/transform.rs +++ b/actix-service/src/transform.rs @@ -1,7 +1,7 @@ use std::rc::Rc; use std::sync::Arc; -use futures::Future; +use futures::IntoFuture; use crate::transform_map_init_err::TransformMapInitErr; use crate::Service; @@ -31,7 +31,7 @@ pub trait Transform { type InitError; /// The future response value. - type Future: Future; + type Future: IntoFuture; /// Create and return a new service value asynchronously. fn new_transform(&self, service: S) -> Self::Future; diff --git a/actix-service/src/transform_map_init_err.rs b/actix-service/src/transform_map_init_err.rs index 0b0dd9b9..3a310068 100644 --- a/actix-service/src/transform_map_init_err.rs +++ b/actix-service/src/transform_map_init_err.rs @@ -1,6 +1,6 @@ use std::marker::PhantomData; -use futures::{Future, Poll}; +use futures::{Future, IntoFuture, Poll}; use super::Transform; @@ -57,7 +57,10 @@ where type Future = TransformMapInitErrFuture; fn new_transform(&self, service: S) -> Self::Future { - TransformMapInitErrFuture::new(self.t.new_transform(service), self.f.clone()) + TransformMapInitErrFuture::new( + self.t.new_transform(service).into_future(), + self.f.clone(), + ) } } @@ -66,7 +69,7 @@ where T: Transform, F: Fn(T::InitError) -> E, { - fut: T::Future, + fut: ::Future, f: F, } @@ -75,7 +78,7 @@ where T: Transform, F: Fn(T::InitError) -> E, { - fn new(fut: T::Future, f: F) -> Self { + fn new(fut: ::Future, f: F) -> Self { TransformMapInitErrFuture { f, fut } } }