diff --git a/src/future/either.rs b/src/future/either.rs new file mode 100644 index 00000000000..fe0425285e8 --- /dev/null +++ b/src/future/either.rs @@ -0,0 +1,23 @@ +use {Future, Poll}; +/// Combines two different futures yielding the same item and error +/// types into a single type. +pub enum Either { + /// First branch of the type + A(A), + /// Second branch of the type + B(B), +} + +impl Future for Either + where A: Future, + B: Future +{ + type Item = Item; + type Error = Error; + fn poll(&mut self) -> Poll { + match *self { + Either::A(ref mut a) => a.poll(), + Either::B(ref mut b) => b.poll(), + } + } +} diff --git a/src/future/mod.rs b/src/future/mod.rs index 2c658ba28ce..b7c1dfe7cb5 100644 --- a/src/future/mod.rs +++ b/src/future/mod.rs @@ -47,6 +47,7 @@ mod map_err; mod or_else; mod select; mod then; +mod either; // impl details mod chain; @@ -62,6 +63,7 @@ pub use self::map_err::MapErr; pub use self::or_else::OrElse; pub use self::select::{Select, SelectNext}; pub use self::then::Then; +pub use self::either::Either; if_std! { mod catch_unwind;