use std::cell::RefCell; use std::rc::Rc; use futures::Poll; use super::service::Service; /// Service that allows to turn non-clone service to a service with `Clone` impl pub struct CloneableService { service: Rc>, } impl CloneableService { pub fn new(service: S) -> Self { Self { service: Rc::new(RefCell::new(service)), } } } impl Clone for CloneableService { fn clone(&self) -> Self { Self { service: self.service.clone(), } } } impl Service for CloneableService { type Request = S::Request; type Response = S::Response; type Error = S::Error; type Future = S::Future; fn poll_ready(&mut self) -> Poll<(), Self::Error> { self.service.borrow_mut().poll_ready() } fn call(&mut self, req: Self::Request) -> Self::Future { self.service.borrow_mut().call(req) } }