1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-30 16:34:36 +01:00

use owned value for service factory config

This commit is contained in:
Nikolay Kim 2019-12-02 21:27:48 +06:00
parent 3385682e09
commit 9ed35cca7a
30 changed files with 112 additions and 143 deletions

View File

@ -49,7 +49,7 @@ impl<T: Address> ServiceFactory for TcpConnectorFactory<T> {
type InitError = (); type InitError = ();
type Future = Ready<Result<Self::Service, Self::InitError>>; type Future = Ready<Result<Self::Service, Self::InitError>>;
fn new_service(&self, _: &()) -> Self::Future { fn new_service(&self, _: ()) -> Self::Future {
ok(self.service()) ok(self.service())
} }
} }

View File

@ -63,7 +63,7 @@ impl<T: Address> ServiceFactory for ResolverFactory<T> {
type InitError = (); type InitError = ();
type Future = Ready<Result<Self::Service, Self::InitError>>; type Future = Ready<Result<Self::Service, Self::InitError>>;
fn new_service(&self, _: &()) -> Self::Future { fn new_service(&self, _: ()) -> Self::Future {
ok(self.service()) ok(self.service())
} }
} }

View File

@ -79,7 +79,7 @@ impl<T: Address> ServiceFactory for ConnectServiceFactory<T> {
type InitError = (); type InitError = ();
type Future = Ready<Result<Self::Service, Self::InitError>>; type Future = Ready<Result<Self::Service, Self::InitError>>;
fn new_service(&self, _: &()) -> Self::Future { fn new_service(&self, _: ()) -> Self::Future {
ok(self.service()) ok(self.service())
} }
} }

View File

@ -66,7 +66,7 @@ where
type InitError = (); type InitError = ();
type Future = Ready<Result<Self::Service, Self::InitError>>; type Future = Ready<Result<Self::Service, Self::InitError>>;
fn new_service(&self, _: &()) -> Self::Future { fn new_service(&self, _: ()) -> Self::Future {
ok(OpensslConnectorService { ok(OpensslConnectorService {
connector: self.connector.clone(), connector: self.connector.clone(),
_t: PhantomData, _t: PhantomData,
@ -201,7 +201,7 @@ impl<T: Address + 'static> ServiceFactory for OpensslConnectServiceFactory<T> {
type InitError = (); type InitError = ();
type Future = Ready<Result<Self::Service, Self::InitError>>; type Future = Ready<Result<Self::Service, Self::InitError>>;
fn new_service(&self, _: &()) -> Self::Future { fn new_service(&self, _: ()) -> Self::Future {
ok(self.service()) ok(self.service())
} }
} }

View File

@ -89,7 +89,7 @@ async fn test_new_service() {
let factory = actix_connect::new_connector_factory(resolver); let factory = actix_connect::new_connector_factory(resolver);
let mut conn = factory.new_service(&()).await.unwrap(); let mut conn = factory.new_service(()).await.unwrap();
let con = conn.call(Connect::with("10", srv.addr())).await.unwrap(); let con = conn.call(Connect::with("10", srv.addr())).await.unwrap();
assert_eq!(con.peer_addr().unwrap(), srv.addr()); assert_eq!(con.peer_addr().unwrap(), srv.addr());
} }

View File

@ -17,7 +17,6 @@ use crate::cell::Cell;
use crate::error::ServiceError; use crate::error::ServiceError;
use crate::item::Item; use crate::item::Item;
use crate::sink::Sink; use crate::sink::Sink;
use crate::state::State;
type Request<S, U> = Item<S, U>; type Request<S, U> = Item<S, U>;
type Response<U> = <U as Encoder>::Item; type Response<U> = <U as Encoder>::Item;
@ -33,6 +32,7 @@ pub(crate) enum FramedMessage<T> {
#[pin_project::pin_project] #[pin_project::pin_project]
pub(crate) struct FramedDispatcher<St, S, T, U> pub(crate) struct FramedDispatcher<St, S, T, U>
where where
St: Clone,
S: Service<Request = Request<St, U>, Response = Option<Response<U>>>, S: Service<Request = Request<St, U>, Response = Option<Response<U>>>,
S::Error: 'static, S::Error: 'static,
S::Future: 'static, S::Future: 'static,
@ -43,7 +43,7 @@ where
{ {
service: S, service: S,
sink: Sink<<U as Encoder>::Item>, sink: Sink<<U as Encoder>::Item>,
state: State<St>, state: St,
dispatch_state: FramedState<S, U>, dispatch_state: FramedState<S, U>,
framed: Framed<T, U>, framed: Framed<T, U>,
rx: Option<mpsc::Receiver<FramedMessage<<U as Encoder>::Item>>>, rx: Option<mpsc::Receiver<FramedMessage<<U as Encoder>::Item>>>,
@ -53,6 +53,7 @@ where
impl<St, S, T, U> FramedDispatcher<St, S, T, U> impl<St, S, T, U> FramedDispatcher<St, S, T, U>
where where
St: Clone,
S: Service<Request = Request<St, U>, Response = Option<Response<U>>>, S: Service<Request = Request<St, U>, Response = Option<Response<U>>>,
S::Error: 'static, S::Error: 'static,
S::Future: 'static, S::Future: 'static,
@ -63,7 +64,7 @@ where
{ {
pub(crate) fn new<F: IntoService<S>>( pub(crate) fn new<F: IntoService<S>>(
framed: Framed<T, U>, framed: Framed<T, U>,
state: State<St>, state: St,
service: F, service: F,
rx: mpsc::Receiver<FramedMessage<<U as Encoder>::Item>>, rx: mpsc::Receiver<FramedMessage<<U as Encoder>::Item>>,
sink: Sink<<U as Encoder>::Item>, sink: Sink<<U as Encoder>::Item>,
@ -124,6 +125,7 @@ struct FramedDispatcherInner<I, E> {
impl<St, S, T, U> FramedDispatcher<St, S, T, U> impl<St, S, T, U> FramedDispatcher<St, S, T, U>
where where
St: Clone,
S: Service<Request = Request<St, U>, Response = Option<Response<U>>>, S: Service<Request = Request<St, U>, Response = Option<Response<U>>>,
S::Error: 'static, S::Error: 'static,
S::Future: 'static, S::Future: 'static,
@ -156,7 +158,7 @@ where
fn poll<St, S, T, U>( fn poll<St, S, T, U>(
cx: &mut Context, cx: &mut Context,
srv: &mut S, srv: &mut S,
state: &mut State<St>, state: &mut St,
sink: &mut Sink<<U as Encoder>::Item>, sink: &mut Sink<<U as Encoder>::Item>,
framed: &mut Framed<T, U>, framed: &mut Framed<T, U>,
dispatch_state: &mut FramedState<S, U>, dispatch_state: &mut FramedState<S, U>,
@ -165,6 +167,7 @@ fn poll<St, S, T, U>(
disconnect: &mut Option<Rc<dyn Fn(&mut St, bool)>>, disconnect: &mut Option<Rc<dyn Fn(&mut St, bool)>>,
) -> Poll<Result<(), ServiceError<S::Error, U>>> ) -> Poll<Result<(), ServiceError<S::Error, U>>>
where where
St: Clone,
S: Service<Request = Request<St, U>, Response = Option<Response<U>>>, S: Service<Request = Request<St, U>, Response = Option<Response<U>>>,
S::Error: 'static, S::Error: 'static,
S::Future: 'static, S::Future: 'static,
@ -199,7 +202,7 @@ where
|| framed.is_write_buf_empty()) || framed.is_write_buf_empty())
{ {
if let Some(ref disconnect) = disconnect { if let Some(ref disconnect) = disconnect {
(&*disconnect)(&mut *state.get_mut(), true); (&*disconnect)(&mut *state, true);
} }
Poll::Ready(Err(err)) Poll::Ready(Err(err))
} else { } else {
@ -224,19 +227,19 @@ where
let _ = tx.send(()); let _ = tx.send(());
} }
if let Some(ref disconnect) = disconnect { if let Some(ref disconnect) = disconnect {
(&*disconnect)(&mut *state.get_mut(), false); (&*disconnect)(&mut *state, false);
} }
Poll::Ready(Ok(())) Poll::Ready(Ok(()))
} }
FramedState::FramedError(err) => { FramedState::FramedError(err) => {
if let Some(ref disconnect) = disconnect { if let Some(ref disconnect) = disconnect {
(&*disconnect)(&mut *state.get_mut(), true); (&*disconnect)(&mut *state, true);
} }
Poll::Ready(Err(err)) Poll::Ready(Err(err))
} }
FramedState::Stopping => { FramedState::Stopping => {
if let Some(ref disconnect) = disconnect { if let Some(ref disconnect) = disconnect {
(&*disconnect)(&mut *state.get_mut(), false); (&*disconnect)(&mut *state, false);
} }
Poll::Ready(Ok(())) Poll::Ready(Ok(()))
} }
@ -246,13 +249,14 @@ where
fn poll_read<St, S, T, U>( fn poll_read<St, S, T, U>(
cx: &mut Context, cx: &mut Context,
srv: &mut S, srv: &mut S,
state: &mut State<St>, state: &mut St,
sink: &mut Sink<<U as Encoder>::Item>, sink: &mut Sink<<U as Encoder>::Item>,
framed: &mut Framed<T, U>, framed: &mut Framed<T, U>,
dispatch_state: &mut FramedState<S, U>, dispatch_state: &mut FramedState<S, U>,
inner: &mut Cell<FramedDispatcherInner<<U as Encoder>::Item, S::Error>>, inner: &mut Cell<FramedDispatcherInner<<U as Encoder>::Item, S::Error>>,
) -> bool ) -> bool
where where
St: Clone,
S: Service<Request = Request<St, U>, Response = Option<Response<U>>>, S: Service<Request = Request<St, U>, Response = Option<Response<U>>>,
S::Error: 'static, S::Error: 'static,
S::Future: 'static, S::Future: 'static,

View File

@ -1,14 +1,12 @@
use std::cell::{Ref, RefMut};
use std::fmt; use std::fmt;
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
use actix_codec::{Decoder, Encoder}; use actix_codec::{Decoder, Encoder};
use crate::sink::Sink; use crate::sink::Sink;
use crate::state::State;
pub struct Item<St, Codec: Encoder + Decoder> { pub struct Item<St, Codec: Encoder + Decoder> {
state: State<St>, state: St,
sink: Sink<<Codec as Encoder>::Item>, sink: Sink<<Codec as Encoder>::Item>,
item: <Codec as Decoder>::Item, item: <Codec as Decoder>::Item,
} }
@ -18,7 +16,7 @@ where
Codec: Encoder + Decoder, Codec: Encoder + Decoder,
{ {
pub(crate) fn new( pub(crate) fn new(
state: State<St>, state: St,
sink: Sink<<Codec as Encoder>::Item>, sink: Sink<<Codec as Encoder>::Item>,
item: <Codec as Decoder>::Item, item: <Codec as Decoder>::Item,
) -> Self { ) -> Self {
@ -26,13 +24,13 @@ where
} }
#[inline] #[inline]
pub fn state(&self) -> Ref<St> { pub fn state(&self) -> &St {
self.state.get_ref() &self.state
} }
#[inline] #[inline]
pub fn state_mut(&mut self) -> RefMut<St> { pub fn state_mut(&mut self) -> &mut St {
self.state.get_mut() &mut self.state
} }
#[inline] #[inline]
@ -46,13 +44,7 @@ where
} }
#[inline] #[inline]
pub fn into_parts( pub fn into_parts(self) -> (St, Sink<<Codec as Encoder>::Item>, <Codec as Decoder>::Item) {
self,
) -> (
State<St>,
Sink<<Codec as Encoder>::Item>,
<Codec as Decoder>::Item,
) {
(self.state, self.sink, self.item) (self.state, self.sink, self.item)
} }
} }

View File

@ -5,11 +5,9 @@ mod error;
mod item; mod item;
mod service; mod service;
mod sink; mod sink;
mod state;
pub use self::connect::{Connect, ConnectResult}; pub use self::connect::{Connect, ConnectResult};
pub use self::error::ServiceError; pub use self::error::ServiceError;
pub use self::item::Item; pub use self::item::Item;
pub use self::service::{Builder, NewServiceBuilder, ServiceBuilder}; pub use self::service::{Builder, NewServiceBuilder, ServiceBuilder};
pub use self::sink::Sink; pub use self::sink::Sink;
pub use self::state::State;

View File

@ -14,7 +14,6 @@ use crate::connect::{Connect, ConnectResult};
use crate::dispatcher::FramedDispatcher; use crate::dispatcher::FramedDispatcher;
use crate::error::ServiceError; use crate::error::ServiceError;
use crate::item::Item; use crate::item::Item;
use crate::state::State;
type RequestItem<S, U> = Item<S, U>; type RequestItem<S, U> = Item<S, U>;
type ResponseItem<U> = Option<<U as Encoder>::Item>; type ResponseItem<U> = Option<<U as Encoder>::Item>;
@ -23,7 +22,7 @@ type ResponseItem<U> = Option<<U as Encoder>::Item>;
/// for building instances for framed services. /// for building instances for framed services.
pub struct Builder<St, Codec>(PhantomData<(St, Codec)>); pub struct Builder<St, Codec>(PhantomData<(St, Codec)>);
impl<St, Codec> Builder<St, Codec> { impl<St: Clone, Codec> Builder<St, Codec> {
pub fn new() -> Builder<St, Codec> { pub fn new() -> Builder<St, Codec> {
Builder(PhantomData) Builder(PhantomData)
} }
@ -73,7 +72,7 @@ pub struct ServiceBuilder<St, C, Io, Codec> {
impl<St, C, Io, Codec> ServiceBuilder<St, C, Io, Codec> impl<St, C, Io, Codec> ServiceBuilder<St, C, Io, Codec>
where where
St: 'static, St: Clone,
C: Service<Request = Connect<Io>, Response = ConnectResult<Io, St, Codec>>, C: Service<Request = Connect<Io>, Response = ConnectResult<Io, St, Codec>>,
C::Error: 'static, C::Error: 'static,
Io: AsyncRead + AsyncWrite, Io: AsyncRead + AsyncWrite,
@ -121,7 +120,7 @@ pub struct NewServiceBuilder<St, C, Io, Codec> {
impl<St, C, Io, Codec> NewServiceBuilder<St, C, Io, Codec> impl<St, C, Io, Codec> NewServiceBuilder<St, C, Io, Codec>
where where
St: 'static, St: Clone,
Io: AsyncRead + AsyncWrite, Io: AsyncRead + AsyncWrite,
C: ServiceFactory< C: ServiceFactory<
Config = (), Config = (),
@ -174,7 +173,7 @@ pub struct FramedService<St, C, T, Io, Codec, Cfg> {
impl<St, C, T, Io, Codec, Cfg> ServiceFactory for FramedService<St, C, T, Io, Codec, Cfg> impl<St, C, T, Io, Codec, Cfg> ServiceFactory for FramedService<St, C, T, Io, Codec, Cfg>
where where
St: 'static, St: Clone + 'static,
Io: AsyncRead + AsyncWrite, Io: AsyncRead + AsyncWrite,
C: ServiceFactory< C: ServiceFactory<
Config = (), Config = (),
@ -203,13 +202,13 @@ where
type Service = FramedServiceImpl<St, C::Service, T, Io, Codec>; type Service = FramedServiceImpl<St, C::Service, T, Io, Codec>;
type Future = LocalBoxFuture<'static, Result<Self::Service, Self::InitError>>; type Future = LocalBoxFuture<'static, Result<Self::Service, Self::InitError>>;
fn new_service(&self, _: &Cfg) -> Self::Future { fn new_service(&self, _: Cfg) -> Self::Future {
let handler = self.handler.clone(); let handler = self.handler.clone();
let disconnect = self.disconnect.clone(); let disconnect = self.disconnect.clone();
// create connect service and then create service impl // create connect service and then create service impl
self.connect self.connect
.new_service(&()) .new_service(())
.map(move |result| { .map(move |result| {
result.map(move |connect| FramedServiceImpl { result.map(move |connect| FramedServiceImpl {
connect, connect,
@ -231,6 +230,7 @@ pub struct FramedServiceImpl<St, C, T, Io, Codec> {
impl<St, C, T, Io, Codec> Service for FramedServiceImpl<St, C, T, Io, Codec> impl<St, C, T, Io, Codec> Service for FramedServiceImpl<St, C, T, Io, Codec>
where where
St: Clone,
Io: AsyncRead + AsyncWrite, Io: AsyncRead + AsyncWrite,
C: Service<Request = Connect<Io>, Response = ConnectResult<Io, St, Codec>>, C: Service<Request = Connect<Io>, Response = ConnectResult<Io, St, Codec>>,
C::Error: 'static, C::Error: 'static,
@ -269,6 +269,7 @@ where
#[pin_project::pin_project] #[pin_project::pin_project]
pub struct FramedServiceImplResponse<St, Io, Codec, C, T> pub struct FramedServiceImplResponse<St, Io, Codec, C, T>
where where
St: Clone,
C: Service<Request = Connect<Io>, Response = ConnectResult<Io, St, Codec>>, C: Service<Request = Connect<Io>, Response = ConnectResult<Io, St, Codec>>,
C::Error: 'static, C::Error: 'static,
T: ServiceFactory< T: ServiceFactory<
@ -290,6 +291,7 @@ where
impl<St, Io, Codec, C, T> Future for FramedServiceImplResponse<St, Io, Codec, C, T> impl<St, Io, Codec, C, T> Future for FramedServiceImplResponse<St, Io, Codec, C, T>
where where
St: Clone,
C: Service<Request = Connect<Io>, Response = ConnectResult<Io, St, Codec>>, C: Service<Request = Connect<Io>, Response = ConnectResult<Io, St, Codec>>,
C::Error: 'static, C::Error: 'static,
T: ServiceFactory< T: ServiceFactory<
@ -325,6 +327,7 @@ where
#[pin_project::pin_project] #[pin_project::pin_project]
enum FramedServiceImplResponseInner<St, Io, Codec, C, T> enum FramedServiceImplResponseInner<St, Io, Codec, C, T>
where where
St: Clone,
C: Service<Request = Connect<Io>, Response = ConnectResult<Io, St, Codec>>, C: Service<Request = Connect<Io>, Response = ConnectResult<Io, St, Codec>>,
C::Error: 'static, C::Error: 'static,
T: ServiceFactory< T: ServiceFactory<
@ -351,6 +354,7 @@ where
impl<St, Io, Codec, C, T> FramedServiceImplResponseInner<St, Io, Codec, C, T> impl<St, Io, Codec, C, T> FramedServiceImplResponseInner<St, Io, Codec, C, T>
where where
St: Clone,
C: Service<Request = Connect<Io>, Response = ConnectResult<Io, St, Codec>>, C: Service<Request = Connect<Io>, Response = ConnectResult<Io, St, Codec>>,
C::Error: 'static, C::Error: 'static,
T: ServiceFactory< T: ServiceFactory<
@ -380,7 +384,7 @@ where
match fut.poll(cx) { match fut.poll(cx) {
Poll::Ready(Ok(res)) => { Poll::Ready(Ok(res)) => {
Either::Left(FramedServiceImplResponseInner::Handler( Either::Left(FramedServiceImplResponseInner::Handler(
handler.new_service(&res.state), handler.new_service(res.state.clone()),
Some(res), Some(res),
disconnect.take(), disconnect.take(),
)) ))
@ -396,7 +400,7 @@ where
Either::Left(FramedServiceImplResponseInner::Dispatcher( Either::Left(FramedServiceImplResponseInner::Dispatcher(
FramedDispatcher::new( FramedDispatcher::new(
res.framed, res.framed,
State::new(res.state), res.state,
handler, handler,
res.rx, res.rx,
res.sink, res.sink,

View File

@ -1,30 +0,0 @@
use std::cell::{Ref, RefCell, RefMut};
use std::rc::Rc;
/// Connection state
///
/// Connection state is an arbitrary data attached to the each incoming message.
#[derive(Debug)]
pub struct State<T>(Rc<RefCell<T>>);
impl<T> State<T> {
pub(crate) fn new(st: T) -> Self {
State(Rc::new(RefCell::new(st)))
}
#[inline]
pub fn get_ref(&self) -> Ref<T> {
self.0.borrow()
}
#[inline]
pub fn get_mut(&mut self) -> RefMut<T> {
self.0.borrow_mut()
}
}
impl<T> Clone for State<T> {
fn clone(&self) -> Self {
State(self.0.clone())
}
}

View File

@ -10,6 +10,7 @@ use futures::future::ok;
use actix_ioframe::{Builder, Connect}; use actix_ioframe::{Builder, Connect};
#[derive(Clone)]
struct State; struct State;
#[actix_rt::test] #[actix_rt::test]

View File

@ -121,7 +121,7 @@ impl InternalServiceFactory for ConfiguredService {
} }
let mut res = vec![]; let mut res = vec![];
for (token, ns) in services.into_iter() { for (token, ns) in services.into_iter() {
let newserv = ns.new_service(&()); let newserv = ns.new_service(());
match newserv.await { match newserv.await {
Ok(serv) => { Ok(serv) => {
res.push((token, serv)); res.push((token, serv));
@ -250,8 +250,8 @@ where
type Service = BoxedServerService; type Service = BoxedServerService;
type Future = LocalBoxFuture<'static, Result<BoxedServerService, ()>>; type Future = LocalBoxFuture<'static, Result<BoxedServerService, ()>>;
fn new_service(&self, cfg: &()) -> Self::Future { fn new_service(&self, _: ()) -> Self::Future {
let fut = self.inner.new_service(cfg); let fut = self.inner.new_service(());
async move { async move {
return match fut.await { return match fut.await {
Ok(s) => Ok(Box::new(StreamService::new(s)) as BoxedServerService), Ok(s) => Ok(Box::new(StreamService::new(s)) as BoxedServerService),

View File

@ -150,7 +150,7 @@ where
let token = self.token; let token = self.token;
self.inner self.inner
.create() .create()
.new_service(&()) .new_service(())
.map_err(|_| ()) .map_err(|_| ())
.map_ok(move |inner| { .map_ok(move |inner| {
let service: BoxedServerService = Box::new(StreamService::new(inner)); let service: BoxedServerService = Box::new(StreamService::new(inner));

View File

@ -134,6 +134,7 @@ where
impl<A, B> AndThenServiceFactory<A, B> impl<A, B> AndThenServiceFactory<A, B>
where where
A: ServiceFactory, A: ServiceFactory,
A::Config: Clone,
B: ServiceFactory< B: ServiceFactory<
Config = A::Config, Config = A::Config,
Request = A::Response, Request = A::Response,
@ -142,7 +143,7 @@ where
>, >,
{ {
/// Create new `AndThenFactory` combinator /// Create new `AndThenFactory` combinator
pub fn new(a: A, b: B) -> Self { pub(crate) fn new(a: A, b: B) -> Self {
Self { a, b } Self { a, b }
} }
} }
@ -150,6 +151,7 @@ where
impl<A, B> ServiceFactory for AndThenServiceFactory<A, B> impl<A, B> ServiceFactory for AndThenServiceFactory<A, B>
where where
A: ServiceFactory, A: ServiceFactory,
A::Config: Clone,
B: ServiceFactory< B: ServiceFactory<
Config = A::Config, Config = A::Config,
Request = A::Response, Request = A::Response,
@ -166,8 +168,11 @@ where
type InitError = A::InitError; type InitError = A::InitError;
type Future = AndThenServiceFactoryResponse<A, B>; type Future = AndThenServiceFactoryResponse<A, B>;
fn new_service(&self, cfg: &A::Config) -> Self::Future { fn new_service(&self, cfg: A::Config) -> Self::Future {
AndThenServiceFactoryResponse::new(self.a.new_service(cfg), self.b.new_service(cfg)) AndThenServiceFactoryResponse::new(
self.a.new_service(cfg.clone()),
self.b.new_service(cfg),
)
} }
} }
@ -318,7 +323,7 @@ mod tests {
pipeline_factory(factory_fn(move || ready(Ok::<_, ()>(Srv1(cnt2.clone()))))) pipeline_factory(factory_fn(move || ready(Ok::<_, ()>(Srv1(cnt2.clone())))))
.and_then(move || ready(Ok(Srv2(cnt.clone())))); .and_then(move || ready(Ok(Srv2(cnt.clone()))));
let mut srv = new_srv.new_service(&()).await.unwrap(); let mut srv = new_srv.new_service(()).await.unwrap();
let res = srv.call("srv1").await; let res = srv.call("srv1").await;
assert!(res.is_ok()); assert!(res.is_ok());
assert_eq!(res.unwrap(), ("srv1", "srv2")); assert_eq!(res.unwrap(), ("srv1", "srv2"));

View File

@ -117,7 +117,7 @@ where
type InitError = T::InitError; type InitError = T::InitError;
type Future = ApplyServiceFactoryResponse<T, F, R, In, Out, Err>; type Future = ApplyServiceFactoryResponse<T, F, R, In, Out, Err>;
fn new_service(&self, cfg: &T::Config) -> Self::Future { fn new_service(&self, cfg: T::Config) -> Self::Future {
ApplyServiceFactoryResponse::new(self.service.new_service(cfg), self.f.clone()) ApplyServiceFactoryResponse::new(self.service.new_service(cfg), self.f.clone())
} }
} }
@ -226,7 +226,7 @@ mod tests {
}, },
)); ));
let mut srv = new_srv.new_service(&()).await.unwrap(); let mut srv = new_srv.new_service(()).await.unwrap();
assert_eq!(lazy(|cx| srv.poll_ready(cx)).await, Poll::Ready(Ok(()))); assert_eq!(lazy(|cx| srv.poll_ready(cx)).await, Poll::Ready(Ok(())));

View File

@ -9,7 +9,7 @@ use crate::{Service, ServiceFactory};
/// Convert `Fn(&Config, &mut Service) -> Future<Service>` fn to a NewService /// Convert `Fn(&Config, &mut Service) -> Future<Service>` fn to a NewService
pub fn apply_cfg<F, C, T, R, S, E>(srv: T, f: F) -> ApplyConfigService<F, C, T, R, S, E> pub fn apply_cfg<F, C, T, R, S, E>(srv: T, f: F) -> ApplyConfigService<F, C, T, R, S, E>
where where
F: FnMut(&C, &mut T) -> R, F: FnMut(C, &mut T) -> R,
T: Service, T: Service,
R: Future<Output = Result<S, E>>, R: Future<Output = Result<S, E>>,
S: Service, S: Service,
@ -28,8 +28,7 @@ pub fn apply_cfg_factory<F, C, T, R, S>(
f: F, f: F,
) -> ApplyConfigServiceFactory<F, C, T, R, S> ) -> ApplyConfigServiceFactory<F, C, T, R, S>
where where
C: Clone, F: FnMut(C, &mut T::Service) -> R,
F: FnMut(&C, &mut T::Service) -> R,
T: ServiceFactory<Config = ()>, T: ServiceFactory<Config = ()>,
T::InitError: From<T::Error>, T::InitError: From<T::Error>,
R: Future<Output = Result<S, T::InitError>>, R: Future<Output = Result<S, T::InitError>>,
@ -45,7 +44,7 @@ where
/// Convert `Fn(&Config) -> Future<Service>` fn to NewService\ /// Convert `Fn(&Config) -> Future<Service>` fn to NewService\
pub struct ApplyConfigService<F, C, T, R, S, E> pub struct ApplyConfigService<F, C, T, R, S, E>
where where
F: FnMut(&C, &mut T) -> R, F: FnMut(C, &mut T) -> R,
T: Service, T: Service,
R: Future<Output = Result<S, E>>, R: Future<Output = Result<S, E>>,
S: Service, S: Service,
@ -57,7 +56,7 @@ where
impl<F, C, T, R, S, E> Clone for ApplyConfigService<F, C, T, R, S, E> impl<F, C, T, R, S, E> Clone for ApplyConfigService<F, C, T, R, S, E>
where where
F: FnMut(&C, &mut T) -> R, F: FnMut(C, &mut T) -> R,
T: Service, T: Service,
R: Future<Output = Result<S, E>>, R: Future<Output = Result<S, E>>,
S: Service, S: Service,
@ -73,7 +72,7 @@ where
impl<F, C, T, R, S, E> ServiceFactory for ApplyConfigService<F, C, T, R, S, E> impl<F, C, T, R, S, E> ServiceFactory for ApplyConfigService<F, C, T, R, S, E>
where where
F: FnMut(&C, &mut T) -> R, F: FnMut(C, &mut T) -> R,
T: Service, T: Service,
R: Future<Output = Result<S, E>>, R: Future<Output = Result<S, E>>,
S: Service, S: Service,
@ -87,7 +86,7 @@ where
type InitError = E; type InitError = E;
type Future = R; type Future = R;
fn new_service(&self, cfg: &C) -> Self::Future { fn new_service(&self, cfg: C) -> Self::Future {
unsafe { (self.f.get_mut_unsafe())(cfg, self.srv.get_mut_unsafe()) } unsafe { (self.f.get_mut_unsafe())(cfg, self.srv.get_mut_unsafe()) }
} }
} }
@ -95,8 +94,7 @@ where
/// Convert `Fn(&Config) -> Future<Service>` fn to NewService /// Convert `Fn(&Config) -> Future<Service>` fn to NewService
pub struct ApplyConfigServiceFactory<F, C, T, R, S> pub struct ApplyConfigServiceFactory<F, C, T, R, S>
where where
C: Clone, F: FnMut(C, &mut T::Service) -> R,
F: FnMut(&C, &mut T::Service) -> R,
T: ServiceFactory<Config = ()>, T: ServiceFactory<Config = ()>,
R: Future<Output = Result<S, T::InitError>>, R: Future<Output = Result<S, T::InitError>>,
S: Service, S: Service,
@ -108,8 +106,7 @@ where
impl<F, C, T, R, S> Clone for ApplyConfigServiceFactory<F, C, T, R, S> impl<F, C, T, R, S> Clone for ApplyConfigServiceFactory<F, C, T, R, S>
where where
C: Clone, F: FnMut(C, &mut T::Service) -> R,
F: FnMut(&C, &mut T::Service) -> R,
T: ServiceFactory<Config = ()>, T: ServiceFactory<Config = ()>,
R: Future<Output = Result<S, T::InitError>>, R: Future<Output = Result<S, T::InitError>>,
S: Service, S: Service,
@ -125,8 +122,7 @@ where
impl<F, C, T, R, S> ServiceFactory for ApplyConfigServiceFactory<F, C, T, R, S> impl<F, C, T, R, S> ServiceFactory for ApplyConfigServiceFactory<F, C, T, R, S>
where where
C: Clone, F: FnMut(C, &mut T::Service) -> R,
F: FnMut(&C, &mut T::Service) -> R,
T: ServiceFactory<Config = ()>, T: ServiceFactory<Config = ()>,
T::InitError: From<T::Error>, T::InitError: From<T::Error>,
R: Future<Output = Result<S, T::InitError>>, R: Future<Output = Result<S, T::InitError>>,
@ -141,13 +137,13 @@ where
type InitError = T::InitError; type InitError = T::InitError;
type Future = ApplyConfigServiceFactoryResponse<F, C, T, R, S>; type Future = ApplyConfigServiceFactoryResponse<F, C, T, R, S>;
fn new_service(&self, cfg: &C) -> Self::Future { fn new_service(&self, cfg: C) -> Self::Future {
ApplyConfigServiceFactoryResponse { ApplyConfigServiceFactoryResponse {
f: self.f.clone(), f: self.f.clone(),
cfg: cfg.clone(), cfg: Some(cfg),
fut: None, fut: None,
srv: None, srv: None,
srv_fut: Some(self.srv.get_ref().new_service(&())), srv_fut: Some(self.srv.get_ref().new_service(())),
_t: PhantomData, _t: PhantomData,
} }
} }
@ -156,14 +152,13 @@ where
#[pin_project::pin_project] #[pin_project::pin_project]
pub struct ApplyConfigServiceFactoryResponse<F, C, T, R, S> pub struct ApplyConfigServiceFactoryResponse<F, C, T, R, S>
where where
C: Clone, F: FnMut(C, &mut T::Service) -> R,
F: FnMut(&C, &mut T::Service) -> R,
T: ServiceFactory<Config = ()>, T: ServiceFactory<Config = ()>,
T::InitError: From<T::Error>, T::InitError: From<T::Error>,
R: Future<Output = Result<S, T::InitError>>, R: Future<Output = Result<S, T::InitError>>,
S: Service, S: Service,
{ {
cfg: C, cfg: Option<C>,
f: Cell<F>, f: Cell<F>,
srv: Option<T::Service>, srv: Option<T::Service>,
#[pin] #[pin]
@ -175,8 +170,7 @@ where
impl<F, C, T, R, S> Future for ApplyConfigServiceFactoryResponse<F, C, T, R, S> impl<F, C, T, R, S> Future for ApplyConfigServiceFactoryResponse<F, C, T, R, S>
where where
C: Clone, F: FnMut(C, &mut T::Service) -> R,
F: FnMut(&C, &mut T::Service) -> R,
T: ServiceFactory<Config = ()>, T: ServiceFactory<Config = ()>,
T::InitError: From<T::Error>, T::InitError: From<T::Error>,
R: Future<Output = Result<S, T::InitError>>, R: Future<Output = Result<S, T::InitError>>,
@ -205,7 +199,7 @@ where
} else if let Some(srv) = this.srv { } else if let Some(srv) = this.srv {
match srv.poll_ready(cx)? { match srv.poll_ready(cx)? {
Poll::Ready(_) => { Poll::Ready(_) => {
let fut = this.f.get_mut()(&this.cfg, srv); let fut = this.f.get_mut()(this.cfg.take().unwrap(), srv);
this = self.as_mut().project(); this = self.as_mut().project();
this.fut.set(Some(fut)); this.fut.set(Some(fut));
continue; continue;

View File

@ -69,7 +69,7 @@ where
type Future = BoxFuture<Self::Service, InitErr>; type Future = BoxFuture<Self::Service, InitErr>;
fn new_service(&self, cfg: &C) -> Self::Future { fn new_service(&self, cfg: C) -> Self::Future {
self.0.new_service(cfg) self.0.new_service(cfg)
} }
} }
@ -104,7 +104,7 @@ where
type Service = BoxService<Req, Res, Err>; type Service = BoxService<Req, Res, Err>;
type Future = BoxFuture<Self::Service, Self::InitError>; type Future = BoxFuture<Self::Service, Self::InitError>;
fn new_service(&self, cfg: &C) -> Self::Future { fn new_service(&self, cfg: C) -> Self::Future {
Box::pin( Box::pin(
self.factory self.factory
.new_service(cfg) .new_service(cfg)

View File

@ -38,7 +38,7 @@ where
/// Create `ServiceFactory` for function that can produce services with configuration /// Create `ServiceFactory` for function that can produce services with configuration
pub fn factory_fn_cfg<F, Fut, Cfg, Srv, Err>(f: F) -> FnServiceConfig<F, Fut, Cfg, Srv, Err> pub fn factory_fn_cfg<F, Fut, Cfg, Srv, Err>(f: F) -> FnServiceConfig<F, Fut, Cfg, Srv, Err>
where where
F: Fn(&Cfg) -> Fut, F: Fn(Cfg) -> Fut,
Fut: Future<Output = Result<Srv, Err>>, Fut: Future<Output = Result<Srv, Err>>,
Srv: Service, Srv: Service,
{ {
@ -146,7 +146,7 @@ where
type InitError = (); type InitError = ();
type Future = Ready<Result<Self::Service, Self::InitError>>; type Future = Ready<Result<Self::Service, Self::InitError>>;
fn new_service(&self, _: &Cfg) -> Self::Future { fn new_service(&self, _: Cfg) -> Self::Future {
ok(FnService::new(self.f.clone())) ok(FnService::new(self.f.clone()))
} }
} }
@ -165,7 +165,7 @@ where
/// Convert `Fn(&Config) -> Future<Service>` fn to NewService /// Convert `Fn(&Config) -> Future<Service>` fn to NewService
pub struct FnServiceConfig<F, Fut, Cfg, Srv, Err> pub struct FnServiceConfig<F, Fut, Cfg, Srv, Err>
where where
F: Fn(&Cfg) -> Fut, F: Fn(Cfg) -> Fut,
Fut: Future<Output = Result<Srv, Err>>, Fut: Future<Output = Result<Srv, Err>>,
Srv: Service, Srv: Service,
{ {
@ -175,7 +175,7 @@ where
impl<F, Fut, Cfg, Srv, Err> FnServiceConfig<F, Fut, Cfg, Srv, Err> impl<F, Fut, Cfg, Srv, Err> FnServiceConfig<F, Fut, Cfg, Srv, Err>
where where
F: Fn(&Cfg) -> Fut, F: Fn(Cfg) -> Fut,
Fut: Future<Output = Result<Srv, Err>>, Fut: Future<Output = Result<Srv, Err>>,
Srv: Service, Srv: Service,
{ {
@ -186,7 +186,7 @@ where
impl<F, Fut, Cfg, Srv, Err> ServiceFactory for FnServiceConfig<F, Fut, Cfg, Srv, Err> impl<F, Fut, Cfg, Srv, Err> ServiceFactory for FnServiceConfig<F, Fut, Cfg, Srv, Err>
where where
F: Fn(&Cfg) -> Fut, F: Fn(Cfg) -> Fut,
Fut: Future<Output = Result<Srv, Err>>, Fut: Future<Output = Result<Srv, Err>>,
Srv: Service, Srv: Service,
{ {
@ -199,7 +199,7 @@ where
type InitError = Err; type InitError = Err;
type Future = Fut; type Future = Fut;
fn new_service(&self, cfg: &Cfg) -> Self::Future { fn new_service(&self, cfg: Cfg) -> Self::Future {
(self.f)(cfg) (self.f)(cfg)
} }
} }
@ -240,7 +240,7 @@ where
type InitError = E; type InitError = E;
type Future = R; type Future = R;
fn new_service(&self, _: &C) -> Self::Future { fn new_service(&self, _: C) -> Self::Future {
(self.f)() (self.f)()
} }
} }

View File

@ -21,7 +21,7 @@ mod transform;
pub use self::apply::{apply_fn, apply_fn_factory}; pub use self::apply::{apply_fn, apply_fn_factory};
pub use self::apply_cfg::{apply_cfg, apply_cfg_factory}; pub use self::apply_cfg::{apply_cfg, apply_cfg_factory};
pub use self::fn_service::{factory_fn, factory_fn_cfg, service_fn, service_fn2}; pub use self::fn_service::{factory_fn, factory_fn_cfg, service_fn, service_fn2};
pub use self::map_config::{map_config, unit_config, MappedConfig}; pub use self::map_config::{map_config, unit_config};
pub use self::pipeline::{pipeline, pipeline_factory, Pipeline, PipelineFactory}; pub use self::pipeline::{pipeline, pipeline_factory, Pipeline, PipelineFactory};
pub use self::transform::{apply, Transform}; pub use self::transform::{apply, Transform};
@ -131,7 +131,7 @@ pub trait ServiceFactory {
type Future: Future<Output = Result<Self::Service, Self::InitError>>; type Future: Future<Output = Result<Self::Service, Self::InitError>>;
/// Create and return a new service value asynchronously. /// Create and return a new service value asynchronously.
fn new_service(&self, cfg: &Self::Config) -> Self::Future; fn new_service(&self, cfg: Self::Config) -> Self::Future;
/// Map this service's output to a different type, returning a new service /// Map this service's output to a different type, returning a new service
/// of the resulting type. /// of the resulting type.
@ -246,7 +246,7 @@ where
type InitError = S::InitError; type InitError = S::InitError;
type Future = S::Future; type Future = S::Future;
fn new_service(&self, cfg: &S::Config) -> S::Future { fn new_service(&self, cfg: S::Config) -> S::Future {
self.as_ref().new_service(cfg) self.as_ref().new_service(cfg)
} }
} }
@ -263,7 +263,7 @@ where
type InitError = S::InitError; type InitError = S::InitError;
type Future = S::Future; type Future = S::Future;
fn new_service(&self, cfg: &S::Config) -> S::Future { fn new_service(&self, cfg: S::Config) -> S::Future {
self.as_ref().new_service(cfg) self.as_ref().new_service(cfg)
} }
} }

View File

@ -151,7 +151,7 @@ where
type InitError = A::InitError; type InitError = A::InitError;
type Future = MapServiceFuture<A, F, Res>; type Future = MapServiceFuture<A, F, Res>;
fn new_service(&self, cfg: &A::Config) -> Self::Future { fn new_service(&self, cfg: A::Config) -> Self::Future {
MapServiceFuture::new(self.a.new_service(cfg), self.f.clone()) MapServiceFuture::new(self.a.new_service(cfg), self.f.clone())
} }
} }

View File

@ -2,16 +2,11 @@ use std::marker::PhantomData;
use super::ServiceFactory; use super::ServiceFactory;
pub enum MappedConfig<'a, T> {
Ref(&'a T),
Owned(T),
}
/// Adapt external config to a config for provided new service /// Adapt external config to a config for provided new service
pub fn map_config<T, F, C>(factory: T, f: F) -> MapConfig<T, F, C> pub fn map_config<T, F, C>(factory: T, f: F) -> MapConfig<T, F, C>
where where
T: ServiceFactory, T: ServiceFactory,
F: Fn(&C) -> MappedConfig<T::Config>, F: Fn(C) -> T::Config,
{ {
MapConfig::new(factory, f) MapConfig::new(factory, f)
} }
@ -36,7 +31,7 @@ impl<A, F, C> MapConfig<A, F, C> {
pub(crate) fn new(a: A, f: F) -> Self pub(crate) fn new(a: A, f: F) -> Self
where where
A: ServiceFactory, A: ServiceFactory,
F: Fn(&C) -> MappedConfig<A::Config>, F: Fn(C) -> A::Config,
{ {
Self { Self {
a, a,
@ -63,7 +58,7 @@ where
impl<A, F, C> ServiceFactory for MapConfig<A, F, C> impl<A, F, C> ServiceFactory for MapConfig<A, F, C>
where where
A: ServiceFactory, A: ServiceFactory,
F: Fn(&C) -> MappedConfig<A::Config>, F: Fn(C) -> A::Config,
{ {
type Request = A::Request; type Request = A::Request;
type Response = A::Response; type Response = A::Response;
@ -74,11 +69,8 @@ where
type InitError = A::InitError; type InitError = A::InitError;
type Future = A::Future; type Future = A::Future;
fn new_service(&self, cfg: &C) -> Self::Future { fn new_service(&self, cfg: C) -> Self::Future {
match (self.f)(cfg) { self.a.new_service((self.f)(cfg))
MappedConfig::Ref(cfg) => self.a.new_service(cfg),
MappedConfig::Owned(cfg) => self.a.new_service(&cfg),
}
} }
} }
@ -123,7 +115,7 @@ where
type InitError = A::InitError; type InitError = A::InitError;
type Future = A::Future; type Future = A::Future;
fn new_service(&self, _: &C) -> Self::Future { fn new_service(&self, _: C) -> Self::Future {
self.a.new_service(&()) self.a.new_service(())
} }
} }

View File

@ -154,7 +154,7 @@ where
type InitError = A::InitError; type InitError = A::InitError;
type Future = MapErrServiceFuture<A, F, E>; type Future = MapErrServiceFuture<A, F, E>;
fn new_service(&self, cfg: &A::Config) -> Self::Future { fn new_service(&self, cfg: A::Config) -> Self::Future {
MapErrServiceFuture::new(self.a.new_service(cfg), self.f.clone()) MapErrServiceFuture::new(self.a.new_service(cfg), self.f.clone())
} }
} }

View File

@ -55,7 +55,7 @@ where
type InitError = E; type InitError = E;
type Future = MapInitErrFuture<A, F, E>; type Future = MapInitErrFuture<A, F, E>;
fn new_service(&self, cfg: &A::Config) -> Self::Future { fn new_service(&self, cfg: A::Config) -> Self::Future {
MapInitErrFuture::new(self.a.new_service(cfg), self.f.clone()) MapInitErrFuture::new(self.a.new_service(cfg), self.f.clone())
} }
} }

View File

@ -145,6 +145,7 @@ impl<T: ServiceFactory> PipelineFactory<T> {
pub fn and_then<F, U>(self, factory: F) -> PipelineFactory<AndThenServiceFactory<T, U>> pub fn and_then<F, U>(self, factory: F) -> PipelineFactory<AndThenServiceFactory<T, U>>
where where
Self: Sized, Self: Sized,
T::Config: Clone,
F: IntoServiceFactory<U>, F: IntoServiceFactory<U>,
U: ServiceFactory< U: ServiceFactory<
Config = T::Config, Config = T::Config,
@ -167,6 +168,7 @@ impl<T: ServiceFactory> PipelineFactory<T> {
pub fn then<F, U>(self, factory: F) -> PipelineFactory<ThenServiceFactory<T, U>> pub fn then<F, U>(self, factory: F) -> PipelineFactory<ThenServiceFactory<T, U>>
where where
Self: Sized, Self: Sized,
T::Config: Clone,
F: IntoServiceFactory<U>, F: IntoServiceFactory<U>,
U: ServiceFactory< U: ServiceFactory<
Config = T::Config, Config = T::Config,
@ -236,7 +238,7 @@ impl<T: ServiceFactory> ServiceFactory for PipelineFactory<T> {
type Future = T::Future; type Future = T::Future;
#[inline] #[inline]
fn new_service(&self, cfg: &T::Config) -> Self::Future { fn new_service(&self, cfg: T::Config) -> Self::Future {
self.factory.new_service(cfg) self.factory.new_service(cfg)
} }
} }

View File

@ -129,6 +129,7 @@ pub struct ThenServiceFactory<A, B> {
impl<A, B> ThenServiceFactory<A, B> impl<A, B> ThenServiceFactory<A, B>
where where
A: ServiceFactory, A: ServiceFactory,
A::Config: Clone,
B: ServiceFactory< B: ServiceFactory<
Config = A::Config, Config = A::Config,
Request = Result<A::Response, A::Error>, Request = Result<A::Response, A::Error>,
@ -145,6 +146,7 @@ where
impl<A, B> ServiceFactory for ThenServiceFactory<A, B> impl<A, B> ServiceFactory for ThenServiceFactory<A, B>
where where
A: ServiceFactory, A: ServiceFactory,
A::Config: Clone,
B: ServiceFactory< B: ServiceFactory<
Config = A::Config, Config = A::Config,
Request = Result<A::Response, A::Error>, Request = Result<A::Response, A::Error>,
@ -161,8 +163,11 @@ where
type InitError = A::InitError; type InitError = A::InitError;
type Future = ThenServiceFactoryResponse<A, B>; type Future = ThenServiceFactoryResponse<A, B>;
fn new_service(&self, cfg: &A::Config) -> Self::Future { fn new_service(&self, cfg: A::Config) -> Self::Future {
ThenServiceFactoryResponse::new(self.a.new_service(cfg), self.b.new_service(cfg)) ThenServiceFactoryResponse::new(
self.a.new_service(cfg.clone()),
self.b.new_service(cfg),
)
} }
} }

View File

@ -125,7 +125,7 @@ where
type InitError = T::InitError; type InitError = T::InitError;
type Future = ApplyTransformFuture<T, S>; type Future = ApplyTransformFuture<T, S>;
fn new_service(&self, cfg: &S::Config) -> Self::Future { fn new_service(&self, cfg: S::Config) -> Self::Future {
ApplyTransformFuture { ApplyTransformFuture {
t_cell: self.t.clone(), t_cell: self.t.clone(),
fut_a: self.s.new_service(cfg), fut_a: self.s.new_service(cfg),

View File

@ -49,7 +49,7 @@ impl<T: AsyncRead + AsyncWrite + Unpin + 'static> ServiceFactory for Acceptor<T>
type InitError = (); type InitError = ();
type Future = Ready<Result<Self::Service, Self::InitError>>; type Future = Ready<Result<Self::Service, Self::InitError>>;
fn new_service(&self, _: &()) -> Self::Future { fn new_service(&self, _: ()) -> Self::Future {
MAX_CONN_COUNTER.with(|conns| { MAX_CONN_COUNTER.with(|conns| {
ok(AcceptorService { ok(AcceptorService {
acceptor: self.acceptor.clone(), acceptor: self.acceptor.clone(),

View File

@ -63,6 +63,7 @@ impl<A, B> Either<A, B> {
pub fn new(left: A, right: B) -> Either<A, B> pub fn new(left: A, right: B) -> Either<A, B>
where where
A: ServiceFactory, A: ServiceFactory,
A::Config: Clone,
B: ServiceFactory< B: ServiceFactory<
Config = A::Config, Config = A::Config,
Response = A::Response, Response = A::Response,
@ -77,6 +78,7 @@ impl<A, B> Either<A, B> {
impl<A, B> ServiceFactory for Either<A, B> impl<A, B> ServiceFactory for Either<A, B>
where where
A: ServiceFactory, A: ServiceFactory,
A::Config: Clone,
B: ServiceFactory< B: ServiceFactory<
Config = A::Config, Config = A::Config,
Response = A::Response, Response = A::Response,
@ -92,11 +94,11 @@ where
type Service = EitherService<A::Service, B::Service>; type Service = EitherService<A::Service, B::Service>;
type Future = EitherNewService<A, B>; type Future = EitherNewService<A, B>;
fn new_service(&self, cfg: &A::Config) -> Self::Future { fn new_service(&self, cfg: A::Config) -> Self::Future {
EitherNewService { EitherNewService {
left: None, left: None,
right: None, right: None,
left_fut: self.left.new_service(cfg), left_fut: self.left.new_service(cfg.clone()),
right_fut: self.right.new_service(cfg), right_fut: self.right.new_service(cfg),
} }
} }

View File

@ -58,7 +58,7 @@ where
type Service = KeepAliveService<R, E, F>; type Service = KeepAliveService<R, E, F>;
type Future = Ready<Result<Self::Service, Self::InitError>>; type Future = Ready<Result<Self::Service, Self::InitError>>;
fn new_service(&self, _: &()) -> Self::Future { fn new_service(&self, _: ()) -> Self::Future {
ok(KeepAliveService::new( ok(KeepAliveService::new(
self.ka, self.ka,
self.time.timer(), self.time.timer(),

View File

@ -51,7 +51,7 @@ impl ServiceFactory for LowResTime {
type Service = LowResTimeService; type Service = LowResTimeService;
type Future = Ready<Result<Self::Service, Self::InitError>>; type Future = Ready<Result<Self::Service, Self::InitError>>;
fn new_service(&self, _: &()) -> Self::Future { fn new_service(&self, _: ()) -> Self::Future {
ok(self.timer()) ok(self.timer())
} }
} }