use std::marker::PhantomData; use futures::{Future, Poll}; use super::Service; pub struct FromErr where A: Service, { service: A, f: PhantomData, } impl> FromErr { pub(crate) fn new(service: A) -> Self { FromErr { service, f: PhantomData, } } } impl Clone for FromErr where A: Service + Clone, E: From, { fn clone(&self) -> Self { FromErr { service: self.service.clone(), f: PhantomData, } } } impl Service for FromErr where A: Service, E: From, { type Request = A::Request; type Response = A::Response; type Error = E; type Future = FromErrFuture; fn poll_ready(&mut self) -> Poll<(), E> { Ok(self.service.poll_ready().map_err(E::from)?) } fn call(&mut self, req: Self::Request) -> Self::Future { FromErrFuture { fut: self.service.call(req), f: PhantomData, } } } pub struct FromErrFuture { fut: A::Future, f: PhantomData, } impl Future for FromErrFuture where A: Service, E: From, { type Item = A::Response; type Error = E; fn poll(&mut self) -> Poll { self.fut.poll().map_err(E::from) } }