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

cleanup clonable service

This commit is contained in:
Nikolay Kim 2018-11-30 11:55:30 -08:00
parent 8108f19580
commit a16ad6b2cd
2 changed files with 19 additions and 12 deletions

View File

@ -57,7 +57,7 @@ tokio-tcp = "0.1"
tokio-timer = "0.2" tokio-timer = "0.2"
tokio-reactor = "0.1" tokio-reactor = "0.1"
tokio-current-thread = "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-proto = "^0.5.0"
trust-dns-resolver = "^0.10.0" trust-dns-resolver = "^0.10.0"

View File

@ -1,4 +1,5 @@
use std::marker::PhantomData; use std::marker::PhantomData;
use std::rc::Rc;
use futures::Poll; use futures::Poll;
@ -6,13 +7,16 @@ use super::cell::Cell;
use super::service::Service; use super::service::Service;
/// Service that allows to turn non-clone service to a service with `Clone` impl /// Service that allows to turn non-clone service to a service with `Clone` impl
pub struct CloneableService<S: Service<R> + 'static, R> { pub struct CloneableService<T: 'static> {
service: Cell<S>, service: Cell<T>,
_t: PhantomData<R>, _t: PhantomData<Rc<()>>,
} }
impl<S: Service<R> + 'static, R> CloneableService<S, R> { impl<T: 'static> CloneableService<T> {
pub fn new(service: S) -> Self { pub fn new<Request>(service: T) -> Self
where
T: Service<Request>,
{
Self { Self {
service: Cell::new(service), service: Cell::new(service),
_t: PhantomData, _t: PhantomData,
@ -20,7 +24,7 @@ impl<S: Service<R> + 'static, R> CloneableService<S, R> {
} }
} }
impl<S: Service<R> + 'static, R> Clone for CloneableService<S, R> { impl<T: 'static> Clone for CloneableService<T> {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
service: self.service.clone(), service: self.service.clone(),
@ -29,16 +33,19 @@ impl<S: Service<R> + 'static, R> Clone for CloneableService<S, R> {
} }
} }
impl<S: Service<R> + 'static, R> Service<R> for CloneableService<S, R> { impl<T: 'static, Request> Service<Request> for CloneableService<T>
type Response = S::Response; where
type Error = S::Error; T: Service<Request>,
type Future = S::Future; {
type Response = T::Response;
type Error = T::Error;
type Future = T::Future;
fn poll_ready(&mut self) -> Poll<(), Self::Error> { fn poll_ready(&mut self) -> Poll<(), Self::Error> {
self.service.borrow_mut().poll_ready() 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) self.service.borrow_mut().call(req)
} }
} }