use std::marker::PhantomData; use std::rc::Rc; use futures::Poll; 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 { service: Cell, _t: PhantomData>, } impl CloneableService { pub fn new(service: T) -> Self where T: Service, { Self { service: Cell::new(service), _t: PhantomData, } } } impl Clone for CloneableService { fn clone(&self) -> Self { Self { service: self.service.clone(), _t: PhantomData, } } } 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: Request) -> Self::Future { self.service.borrow_mut().call(req) } }