summaryrefslogtreecommitdiffstats
path: root/third_party/rust/futures-0.1.29/src/future/from_err.rs
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/futures-0.1.29/src/future/from_err.rs')
-rw-r--r--third_party/rust/futures-0.1.29/src/future/from_err.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/third_party/rust/futures-0.1.29/src/future/from_err.rs b/third_party/rust/futures-0.1.29/src/future/from_err.rs
new file mode 100644
index 0000000000..97e35d7cc7
--- /dev/null
+++ b/third_party/rust/futures-0.1.29/src/future/from_err.rs
@@ -0,0 +1,35 @@
+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<A, E> where A: Future {
+ future: A,
+ f: PhantomData<E>
+}
+
+pub fn new<A, E>(future: A) -> FromErr<A, E>
+ where A: Future
+{
+ FromErr {
+ future: future,
+ f: PhantomData
+ }
+}
+
+impl<A:Future, E:From<A::Error>> Future for FromErr<A, E> {
+ type Item = A::Item;
+ type Error = E;
+
+ fn poll(&mut self) -> Poll<A::Item, E> {
+ let e = match self.future.poll() {
+ Ok(Async::NotReady) => return Ok(Async::NotReady),
+ other => other,
+ };
+ e.map_err(From::from)
+ }
+}