mirror of
https://github.com/fafhrd91/actix-net
synced 2025-02-07 15:54:24 +01:00
better ergonomics for aply combinator
This commit is contained in:
parent
a4ba7cd5d4
commit
a91b9a2f9e
@ -2,7 +2,7 @@ use std::marker::PhantomData;
|
|||||||
|
|
||||||
use futures::{Async, Future, IntoFuture, Poll};
|
use futures::{Async, Future, IntoFuture, Poll};
|
||||||
|
|
||||||
use super::{IntoNewService, NewService, Service};
|
use super::{IntoNewService, IntoService, NewService, Service};
|
||||||
|
|
||||||
/// `Apply` service combinator
|
/// `Apply` service combinator
|
||||||
pub struct Apply<T, F, R, Req> {
|
pub struct Apply<T, F, R, Req> {
|
||||||
@ -19,9 +19,9 @@ where
|
|||||||
R: IntoFuture,
|
R: IntoFuture,
|
||||||
{
|
{
|
||||||
/// Create new `Apply` combinator
|
/// Create new `Apply` combinator
|
||||||
pub fn new(service: T, f: F) -> Self {
|
pub fn new<I: IntoService<T>>(service: I, f: F) -> Self {
|
||||||
Self {
|
Self {
|
||||||
service,
|
service: service.into_service(),
|
||||||
f,
|
f,
|
||||||
r: PhantomData,
|
r: PhantomData,
|
||||||
}
|
}
|
||||||
|
@ -24,16 +24,20 @@ pub use self::map_init_err::MapInitErr;
|
|||||||
/// An extension trait for `Service`s that provides a variety of convenient
|
/// An extension trait for `Service`s that provides a variety of convenient
|
||||||
/// adapters
|
/// adapters
|
||||||
pub trait ServiceExt: Service {
|
pub trait ServiceExt: Service {
|
||||||
/// Apply function to specified service and use it as a next service in chain.
|
/// Apply function to specified service and use it as a next service in
|
||||||
fn apply<S, F, R>(self, service: S, f: F) -> AndThen<Self, Apply<S, F, R, Self::Response>>
|
/// chain.
|
||||||
|
fn apply<S, I, F, R>(
|
||||||
|
self, service: I, f: F,
|
||||||
|
) -> AndThen<Self, Apply<S, F, R, Self::Response>>
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
S: Service,
|
S: Service,
|
||||||
S::Error: Into<<R::Future as Future>::Error>,
|
S::Error: Into<<R::Future as Future>::Error>,
|
||||||
|
I: IntoService<S>,
|
||||||
F: Fn(Self::Response, &mut S) -> R,
|
F: Fn(Self::Response, &mut S) -> R,
|
||||||
R: IntoFuture<Error = Self::Error>,
|
R: IntoFuture<Error = Self::Error>,
|
||||||
{
|
{
|
||||||
self.and_then(Apply::new(service, f))
|
self.and_then(Apply::new(service.into_service(), f))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Call another service after call to this one has resolved successfully.
|
/// Call another service after call to this one has resolved successfully.
|
||||||
@ -102,13 +106,14 @@ pub trait ServiceExt: Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub trait NewServiceExt: NewService {
|
pub trait NewServiceExt: NewService {
|
||||||
fn apply<S, F, R>(
|
fn apply<S, I, F, R>(
|
||||||
self, service: S, f: F,
|
self, service: I, f: F,
|
||||||
) -> AndThenNewService<Self, ApplyNewService<S, F, R, Self::Response>>
|
) -> AndThenNewService<Self, ApplyNewService<S, F, R, Self::Response>>
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
S: NewService<InitError = Self::InitError>,
|
S: NewService<InitError = Self::InitError>,
|
||||||
S::Error: Into<<R::Future as Future>::Error>,
|
S::Error: Into<<R::Future as Future>::Error>,
|
||||||
|
I: IntoNewService<S>,
|
||||||
F: Fn(Self::Response, &mut S::Service) -> R + Clone,
|
F: Fn(Self::Response, &mut S::Service) -> R + Clone,
|
||||||
R: IntoFuture<Error = Self::Error>,
|
R: IntoFuture<Error = Self::Error>,
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user