use core::marker::PhantomData; use {Future, Poll, Async}; /// Future for the `from_err` combinator, changing the error type of a future. /// /// This is created by the `Future::from_err` method. #[derive(Debug)] #[must_use = "futures do nothing unless polled"] pub struct FromErr where A: Future { future: A, f: PhantomData } pub fn new(future: A) -> FromErr where A: Future { FromErr { future: future, f: PhantomData } } impl> Future for FromErr { type Item = A::Item; type Error = E; fn poll(&mut self) -> Poll { let e = match self.future.poll() { Ok(Async::NotReady) => return Ok(Async::NotReady), other => other, }; e.map_err(From::from) } }