Skip to content

Commit

Permalink
Merge pull request rust-lang#271 from pijul/master
Browse files Browse the repository at this point in the history
Combinator to merge two futures yielding the same types
  • Loading branch information
alexcrichton authored Dec 8, 2016
2 parents 9a0ab4a + 24d2376 commit b66309f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/future/either.rs
Original file line number Diff line number Diff line change
@@ -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<A, B> {
/// First branch of the type
A(A),
/// Second branch of the type
B(B),
}

impl<A, B, Item, Error> Future for Either<A, B>
where A: Future<Item = Item, Error = Error>,
B: Future<Item = Item, Error = Error>
{
type Item = Item;
type Error = Error;
fn poll(&mut self) -> Poll<Item, Error> {
match *self {
Either::A(ref mut a) => a.poll(),
Either::B(ref mut b) => b.poll(),
}
}
}
2 changes: 2 additions & 0 deletions src/future/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ mod map_err;
mod or_else;
mod select;
mod then;
mod either;

// impl details
mod chain;
Expand All @@ -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;
Expand Down

0 comments on commit b66309f

Please sign in to comment.