mirror of
https://github.com/fafhrd91/actix-net
synced 2025-01-18 13:01:49 +01:00
change to IntoFuture
This commit is contained in:
parent
700abc997e
commit
ed14e6b8ea
@ -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
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "actix-service"
|
||||
version = "0.3.1"
|
||||
version = "0.3.2"
|
||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||
description = "Actix Service"
|
||||
keywords = ["network", "framework", "async", "futures"]
|
||||
|
@ -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<A, B, C>;
|
||||
|
||||
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<C>,
|
||||
B: NewService<C, Request = A::Response>,
|
||||
{
|
||||
fut_b: B::Future,
|
||||
fut_a: A::Future,
|
||||
fut_b: <B::Future as IntoFuture>::Future,
|
||||
fut_a: <A::Future as IntoFuture>::Future,
|
||||
a: Option<A::Service>,
|
||||
b: Option<B::Service>,
|
||||
}
|
||||
@ -176,7 +179,10 @@ where
|
||||
A: NewService<C>,
|
||||
B: NewService<C, Request = A::Response>,
|
||||
{
|
||||
fn new(fut_a: A::Future, fut_b: B::Future) -> Self {
|
||||
fn new(
|
||||
fut_a: <A::Future as IntoFuture>::Future,
|
||||
fut_b: <B::Future as IntoFuture>::Future,
|
||||
) -> Self {
|
||||
AndThenNewServiceFuture {
|
||||
fut_a,
|
||||
fut_b,
|
||||
|
@ -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<T, A, B, C> {
|
||||
pub struct AndThenTransform<T, A, B, C> {
|
||||
a: A,
|
||||
b: B,
|
||||
t: Rc<T>,
|
||||
_t: std::marker::PhantomData<C>,
|
||||
}
|
||||
|
||||
impl<T, A, B, C> AndThenTransformNewService<T, A, B, C>
|
||||
impl<T, A, B, C> AndThenTransform<T, A, B, C>
|
||||
where
|
||||
A: NewService<C>,
|
||||
B: NewService<C, InitError = A::InitError>,
|
||||
@ -32,7 +32,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, A, B, C> Clone for AndThenTransformNewService<T, A, B, C>
|
||||
impl<T, A, B, C> Clone for AndThenTransform<T, A, B, C>
|
||||
where
|
||||
A: Clone,
|
||||
B: Clone,
|
||||
@ -47,7 +47,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, A, B, C> NewService<C> for AndThenTransformNewService<T, A, B, C>
|
||||
impl<T, A, B, C> NewService<C> for AndThenTransform<T, A, B, C>
|
||||
where
|
||||
A: NewService<C>,
|
||||
B: NewService<C, InitError = A::InitError>,
|
||||
@ -60,36 +60,36 @@ where
|
||||
|
||||
type InitError = T::InitError;
|
||||
type Service = AndThen<FromErr<A::Service, T::Error>, T::Transform>;
|
||||
type Future = AndThenTransformNewServiceFuture<T, A, B, C>;
|
||||
type Future = AndThenTransformFuture<T, A, B, C>;
|
||||
|
||||
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<T, A, B, C>
|
||||
pub struct AndThenTransformFuture<T, A, B, C>
|
||||
where
|
||||
A: NewService<C>,
|
||||
B: NewService<C, InitError = A::InitError>,
|
||||
T: Transform<B::Service, Request = A::Response, InitError = A::InitError>,
|
||||
T::Error: From<A::Error>,
|
||||
{
|
||||
fut_a: A::Future,
|
||||
fut_b: B::Future,
|
||||
fut_t: Option<T::Future>,
|
||||
fut_a: <A::Future as IntoFuture>::Future,
|
||||
fut_b: <B::Future as IntoFuture>::Future,
|
||||
fut_t: Option<<T::Future as IntoFuture>::Future>,
|
||||
a: Option<A::Service>,
|
||||
t: Option<T::Transform>,
|
||||
t_cell: Rc<T>,
|
||||
}
|
||||
|
||||
impl<T, A, B, C> Future for AndThenTransformNewServiceFuture<T, A, B, C>
|
||||
impl<T, A, B, C> Future for AndThenTransformFuture<T, A, B, C>
|
||||
where
|
||||
A: NewService<C>,
|
||||
B: NewService<C, InitError = A::InitError>,
|
||||
@ -102,7 +102,7 @@ where
|
||||
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<A::Error>,
|
||||
{
|
||||
fut_b: B::Future,
|
||||
fut_a: A::Future,
|
||||
fut_b: <B::Future as IntoFuture>::Future,
|
||||
fut_a: <A::Future as IntoFuture>::Future,
|
||||
f: Cell<F>,
|
||||
a: Option<A::Service>,
|
||||
b: Option<B::Service>,
|
||||
|
@ -124,7 +124,7 @@ where
|
||||
type Future = ApplyNewServiceFuture<T, F, In, Out, Cfg>;
|
||||
|
||||
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: <T::Future as IntoFuture>::Future,
|
||||
f: Option<F>,
|
||||
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: <T::Future as IntoFuture>::Future, f: F) -> Self {
|
||||
ApplyNewServiceFuture {
|
||||
f: Some(f),
|
||||
fut,
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::{NewService, Service};
|
||||
use futures::{Future, Poll};
|
||||
use futures::{Future, IntoFuture, Poll};
|
||||
|
||||
pub type BoxedService<Req, Res, Err> = Box<
|
||||
Service<
|
||||
@ -96,7 +96,12 @@ where
|
||||
type Future = Box<Future<Item = Self::Service, Error = Self::InitError>>;
|
||||
|
||||
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),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<C>,
|
||||
E: From<A::Error>,
|
||||
{
|
||||
fut: A::Future,
|
||||
fut: <A::Future as IntoFuture>::Future,
|
||||
e: PhantomData<E>,
|
||||
}
|
||||
|
||||
|
@ -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<Config = ()> {
|
||||
type InitError;
|
||||
|
||||
/// The future of the `Service` instance.
|
||||
type Future: Future<Item = Self::Service, Error = Self::InitError>;
|
||||
type Future: IntoFuture<Item = Self::Service, Error = Self::InitError>;
|
||||
|
||||
/// Create and return a new service value asynchronously.
|
||||
fn new_service(&self, cfg: &Config) -> Self::Future;
|
||||
@ -210,7 +210,7 @@ pub trait NewService<Config = ()> {
|
||||
self,
|
||||
transform: T1,
|
||||
service: B1,
|
||||
) -> AndThenTransformNewService<T, Self, B, Config>
|
||||
) -> AndThenTransform<T, Self, B, Config>
|
||||
where
|
||||
Self: Sized,
|
||||
T: Transform<B::Service, Request = Self::Response, InitError = Self::InitError>,
|
||||
@ -219,11 +219,7 @@ pub trait NewService<Config = ()> {
|
||||
B: NewService<Config, InitError = Self::InitError>,
|
||||
B1: IntoNewService<B, Config>,
|
||||
{
|
||||
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
|
||||
|
@ -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<A, F, Res, Cfg>;
|
||||
|
||||
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<Cfg>,
|
||||
F: FnMut(A::Response) -> Res,
|
||||
{
|
||||
fut: A::Future,
|
||||
fut: <A::Future as IntoFuture>::Future,
|
||||
f: Option<F>,
|
||||
}
|
||||
|
||||
@ -164,7 +164,7 @@ where
|
||||
A: NewService<Cfg>,
|
||||
F: FnMut(A::Response) -> Res,
|
||||
{
|
||||
fn new(fut: A::Future, f: F) -> Self {
|
||||
fn new(fut: <A::Future as IntoFuture>::Future, f: F) -> Self {
|
||||
MapNewServiceFuture { f: Some(f), fut }
|
||||
}
|
||||
}
|
||||
|
@ -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<A, F, E, C>;
|
||||
|
||||
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<C>,
|
||||
F: Fn(A::Error) -> E,
|
||||
{
|
||||
fut: A::Future,
|
||||
fut: <A::Future as IntoFuture>::Future,
|
||||
f: F,
|
||||
}
|
||||
|
||||
@ -165,7 +165,7 @@ where
|
||||
A: NewService<C>,
|
||||
F: Fn(A::Error) -> E,
|
||||
{
|
||||
fn new(fut: A::Future, f: F) -> Self {
|
||||
fn new(fut: <A::Future as IntoFuture>::Future, f: F) -> Self {
|
||||
MapErrNewServiceFuture { f, fut }
|
||||
}
|
||||
}
|
||||
|
@ -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<A, F, E, C>;
|
||||
|
||||
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: <A::Future as IntoFuture>::Future,
|
||||
}
|
||||
|
||||
impl<A, F, E, C> MapInitErrFuture<A, F, E, C>
|
||||
@ -72,7 +72,7 @@ where
|
||||
A: NewService<C>,
|
||||
F: Fn(A::InitError) -> E,
|
||||
{
|
||||
fn new(fut: A::Future, f: F) -> Self {
|
||||
fn new(fut: <A::Future as IntoFuture>::Future, f: F) -> Self {
|
||||
MapInitErrFuture { f, fut }
|
||||
}
|
||||
}
|
||||
|
@ -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<A, B, C>;
|
||||
|
||||
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: <B::Future as IntoFuture>::Future,
|
||||
fut_a: <A::Future as IntoFuture>::Future,
|
||||
a: Option<A::Service>,
|
||||
b: Option<B::Service>,
|
||||
}
|
||||
@ -201,7 +204,10 @@ where
|
||||
InitError = A::InitError,
|
||||
>,
|
||||
{
|
||||
fn new(fut_a: A::Future, fut_b: B::Future) -> Self {
|
||||
fn new(
|
||||
fut_a: <A::Future as IntoFuture>::Future,
|
||||
fut_b: <B::Future as IntoFuture>::Future,
|
||||
) -> Self {
|
||||
ThenNewServiceFuture {
|
||||
fut_a,
|
||||
fut_b,
|
||||
|
@ -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<S> {
|
||||
type InitError;
|
||||
|
||||
/// The future response value.
|
||||
type Future: Future<Item = Self::Transform, Error = Self::InitError>;
|
||||
type Future: IntoFuture<Item = Self::Transform, Error = Self::InitError>;
|
||||
|
||||
/// Create and return a new service value asynchronously.
|
||||
fn new_transform(&self, service: S) -> Self::Future;
|
||||
|
@ -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<T, S, F, E>;
|
||||
|
||||
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<S>,
|
||||
F: Fn(T::InitError) -> E,
|
||||
{
|
||||
fut: T::Future,
|
||||
fut: <T::Future as IntoFuture>::Future,
|
||||
f: F,
|
||||
}
|
||||
|
||||
@ -75,7 +78,7 @@ where
|
||||
T: Transform<S>,
|
||||
F: Fn(T::InitError) -> E,
|
||||
{
|
||||
fn new(fut: T::Future, f: F) -> Self {
|
||||
fn new(fut: <T::Future as IntoFuture>::Future, f: F) -> Self {
|
||||
TransformMapInitErrFuture { f, fut }
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user