1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-23 21:51:06 +01:00

add IntoConfigurableNewService

This commit is contained in:
Nikolay Kim 2019-02-22 14:30:00 -08:00
parent 6b4010892d
commit 83a19e9cb3
2 changed files with 29 additions and 11 deletions

View File

@ -3,7 +3,7 @@ use std::marker::PhantomData;
use futures::future::{ok, FutureResult};
use futures::{Async, IntoFuture, Poll};
use super::{IntoNewService, IntoService, NewService, Service};
use super::{IntoConfigurableNewService, IntoNewService, IntoService, NewService, Service};
/// Create `NewService` for function that can act as Service
pub fn fn_service<F, Req, Out>(f: F) -> FnNewService<F, Req, Out, ()>
@ -266,13 +266,13 @@ where
}
}
// impl<F, C, R, S, E> IntoNewService<FnNewServiceConfig<F, C, R, S, E>, C> for F
// where
// F: Fn(&C) -> R,
// R: IntoFuture<Item = S, Error = E>,
// S: Service,
// {
// fn into_new_service(self) -> FnNewServiceConfig<F, C, R, S, E> {
// FnNewServiceConfig::new(self)
// }
// }
impl<F, C, R, S, E> IntoConfigurableNewService<FnNewServiceConfig<F, C, R, S, E>, C> for F
where
F: Fn(&C) -> R,
R: IntoFuture<Item = S, Error = E>,
S: Service,
{
fn into_new_service(self) -> FnNewServiceConfig<F, C, R, S, E> {
FnNewServiceConfig::new(self)
}
}

View File

@ -437,3 +437,21 @@ where
self
}
}
/// Trait for types that can be converted to a configurable `NewService`
pub trait IntoConfigurableNewService<T, C>
where
T: NewService<C>,
{
/// Convert to an `NewService`
fn into_new_service(self) -> T;
}
impl<T, C> IntoConfigurableNewService<T, C> for T
where
T: NewService<C>,
{
fn into_new_service(self) -> T {
self
}
}