From 983223a83965559885a065adffee97bb6379aa0e Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Wed, 5 Sep 2018 13:54:15 -0700 Subject: [PATCH] add clone impls for combinator services --- src/service/and_then.rs | 13 +++++++++++++ src/service/apply.rs | 16 ++++++++++++++++ src/service/fn_state_service.rs | 17 +++++++++++++++++ src/service/map.rs | 17 +++++++++++++++-- src/service/map_err.rs | 14 ++++++++++++++ 5 files changed, 75 insertions(+), 2 deletions(-) diff --git a/src/service/and_then.rs b/src/service/and_then.rs index 5b0a65f38..ef3a31146 100644 --- a/src/service/and_then.rs +++ b/src/service/and_then.rs @@ -26,6 +26,19 @@ where } } +impl Clone for AndThen +where + A: Service + Clone, + B: Service, +{ + fn clone(&self) -> Self { + AndThen { + a: self.a.clone(), + b: self.b.clone(), + } + } +} + impl Service for AndThen where A: Service, diff --git a/src/service/apply.rs b/src/service/apply.rs index 58755f6fa..0c29b81c3 100644 --- a/src/service/apply.rs +++ b/src/service/apply.rs @@ -27,6 +27,22 @@ where } } +impl Clone for Apply +where + T: Service + Clone, + T::Error: Into<::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 Service for Apply where T: Service, diff --git a/src/service/fn_state_service.rs b/src/service/fn_state_service.rs index 4a76ee363..8b44ce448 100644 --- a/src/service/fn_state_service.rs +++ b/src/service/fn_state_service.rs @@ -33,6 +33,23 @@ where } } +impl Clone for FnStateService +where + S: Clone, + F: Fn(&mut S, Req) -> Fut + Clone, + Fut: IntoFuture, +{ + fn clone(&self) -> Self { + FnStateService { + f: self.f.clone(), + state: self.state.clone(), + req: marker::PhantomData, + resp: marker::PhantomData, + err: marker::PhantomData, + } + } +} + impl Service for FnStateService where F: Fn(&mut S, Req) -> Fut, diff --git a/src/service/map.rs b/src/service/map.rs index ac2cb4809..9fa2acf6f 100644 --- a/src/service/map.rs +++ b/src/service/map.rs @@ -25,11 +25,24 @@ where } } +impl Clone for Map +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 Service for Map where A: Service, - F: Fn(A::Response) -> R, - F: Clone, + F: Fn(A::Response) -> R + Clone, { type Request = A::Request; type Response = R; diff --git a/src/service/map_err.rs b/src/service/map_err.rs index bf5199802..b05b635ae 100644 --- a/src/service/map_err.rs +++ b/src/service/map_err.rs @@ -25,6 +25,20 @@ where } } +impl Clone for MapErr +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 Service for MapErr where A: Service,