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

add clone impls for combinator services

This commit is contained in:
Nikolay Kim 2018-09-05 13:54:15 -07:00
parent 8540d81dcf
commit 983223a839
5 changed files with 75 additions and 2 deletions

View File

@ -26,6 +26,19 @@ where
}
}
impl<A, B> Clone for AndThen<A, B>
where
A: Service + Clone,
B: Service<Request = A::Response, Error = A::Error>,
{
fn clone(&self) -> Self {
AndThen {
a: self.a.clone(),
b: self.b.clone(),
}
}
}
impl<A, B> Service for AndThen<A, B>
where
A: Service,

View File

@ -27,6 +27,22 @@ where
}
}
impl<T, F, R, Req> Clone for Apply<T, F, R, Req>
where
T: Service + Clone,
T::Error: Into<<R::Future as Future>::Error>,
F: Fn(Req, &mut T) -> R + Clone,
R: IntoFuture,
{
fn clone(&self) -> Self {
Apply {
service: self.service.clone(),
f: self.f.clone(),
r: PhantomData,
}
}
}
impl<T, F, R, Req> Service for Apply<T, F, R, Req>
where
T: Service,

View File

@ -33,6 +33,23 @@ where
}
}
impl<S, F, Req, Resp, Err, Fut> Clone for FnStateService<S, F, Req, Resp, Err, Fut>
where
S: Clone,
F: Fn(&mut S, Req) -> Fut + Clone,
Fut: IntoFuture<Item = Resp, Error = Err>,
{
fn clone(&self) -> Self {
FnStateService {
f: self.f.clone(),
state: self.state.clone(),
req: marker::PhantomData,
resp: marker::PhantomData,
err: marker::PhantomData,
}
}
}
impl<S, F, Req, Resp, Err, Fut> Service for FnStateService<S, F, Req, Resp, Err, Fut>
where
F: Fn(&mut S, Req) -> Fut,

View File

@ -25,11 +25,24 @@ where
}
}
impl<A, F, R> Clone for Map<A, F, R>
where
A: Service + Clone,
F: Fn(A::Response) -> R + Clone,
{
fn clone(&self) -> Self {
Map {
a: self.a.clone(),
f: self.f.clone(),
r: marker::PhantomData,
}
}
}
impl<A, F, R> Service for Map<A, F, R>
where
A: Service,
F: Fn(A::Response) -> R,
F: Clone,
F: Fn(A::Response) -> R + Clone,
{
type Request = A::Request;
type Response = R;

View File

@ -25,6 +25,20 @@ where
}
}
impl<A, F, E> Clone for MapErr<A, F, E>
where
A: Service + Clone,
F: Fn(A::Error) -> E + Clone,
{
fn clone(&self) -> Self {
MapErr {
a: self.a.clone(),
f: self.f.clone(),
e: marker::PhantomData,
}
}
}
impl<A, F, E> Service for MapErr<A, F, E>
where
A: Service,