use std::marker::PhantomData; use std::rc::Rc; use actix_service::Service; use futures::Poll; use super::cell::Cell; /// 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 + 'static, { type Request = T::Request; type Response = T::Response; type Error = T::Error; type Future = T::Future; fn poll_ready(&mut self) -> Poll<(), Self::Error> { self.service.get_mut().poll_ready() } fn call(&mut self, req: T::Request) -> Self::Future { self.service.get_mut().call(req) } }