From a16ad6b2cd539989e8c196cdc84c18af95b4d876 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Fri, 30 Nov 2018 11:55:30 -0800 Subject: [PATCH] cleanup clonable service --- Cargo.toml | 2 +- src/cloneable.rs | 29 ++++++++++++++++++----------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f3638408..2acf028c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,7 +57,7 @@ tokio-tcp = "0.1" tokio-timer = "0.2" tokio-reactor = "0.1" tokio-current-thread = "0.1" -tower-service = { path="../../actix/tower/tower-service/" } +tower-service = { git = "https://github.com/tower-rs/tower.git" } trust-dns-proto = "^0.5.0" trust-dns-resolver = "^0.10.0" diff --git a/src/cloneable.rs b/src/cloneable.rs index 1e388ec1..e367043a 100644 --- a/src/cloneable.rs +++ b/src/cloneable.rs @@ -1,4 +1,5 @@ use std::marker::PhantomData; +use std::rc::Rc; use futures::Poll; @@ -6,13 +7,16 @@ use super::cell::Cell; use super::service::Service; /// Service that allows to turn non-clone service to a service with `Clone` impl -pub struct CloneableService + 'static, R> { - service: Cell, - _t: PhantomData, +pub struct CloneableService { + service: Cell, + _t: PhantomData>, } -impl + 'static, R> CloneableService { - pub fn new(service: S) -> Self { +impl CloneableService { + pub fn new(service: T) -> Self + where + T: Service, + { Self { service: Cell::new(service), _t: PhantomData, @@ -20,7 +24,7 @@ impl + 'static, R> CloneableService { } } -impl + 'static, R> Clone for CloneableService { +impl Clone for CloneableService { fn clone(&self) -> Self { Self { service: self.service.clone(), @@ -29,16 +33,19 @@ impl + 'static, R> Clone for CloneableService { } } -impl + 'static, R> Service for CloneableService { - type Response = S::Response; - type Error = S::Error; - type Future = S::Future; +impl Service for CloneableService +where + T: Service, +{ + type Response = T::Response; + type Error = T::Error; + type Future = T::Future; fn poll_ready(&mut self) -> Poll<(), Self::Error> { self.service.borrow_mut().poll_ready() } - fn call(&mut self, req: R) -> Self::Future { + fn call(&mut self, req: Request) -> Self::Future { self.service.borrow_mut().call(req) } }