From f9b9031af2a5ff9245867e872ce0be3b5925ca6e Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 27 Aug 2018 20:32:49 -0700 Subject: [PATCH] add clone impls --- src/connector.rs | 14 +++++++++++++- src/service/fn_service.rs | 15 +++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/connector.rs b/src/connector.rs index 5752228c..786e4762 100644 --- a/src/connector.rs +++ b/src/connector.rs @@ -2,7 +2,7 @@ use std::collections::VecDeque; use std::io; use std::net::SocketAddr; -use futures::{Async, Future, Poll}; +use futures::{Async, Future, Poll, future::ok}; use tokio; use tokio_tcp::{ConnectFuture, TcpStream}; use tower_service::Service; @@ -47,6 +47,18 @@ impl Connector { Connector { resolver } } + + pub fn new_service() -> impl Future { + ok(Connector::new()) + } +} + +impl Clone for Connector { + fn clone(&self) -> Self { + Connector { + resolver: self.resolver.clone(), + } + } } impl Service for Connector { diff --git a/src/service/fn_service.rs b/src/service/fn_service.rs index 021c2203..28a7df8e 100644 --- a/src/service/fn_service.rs +++ b/src/service/fn_service.rs @@ -34,6 +34,21 @@ where } } +impl Clone for FnService +where + F: Fn(Req) -> Fut + Clone, + Fut: IntoFuture, +{ + fn clone(&self) -> Self { + FnService { + f: self.f.clone(), + req: marker::PhantomData, + resp: marker::PhantomData, + err: marker::PhantomData, + } + } +} + impl Service for FnService where F: Fn(Req) -> Fut,