forked from rust-lang/rfcs
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request rust-lang#271 from pijul/master
Combinator to merge two futures yielding the same types
- Loading branch information
Showing
2 changed files
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters