1 use {Future, Poll}; 2 3 /// Combines two different futures yielding the same item and error 4 /// types into a single type. 5 #[derive(Debug)] 6 pub enum Either<A, B> { 7 /// First branch of the type 8 A(A), 9 /// Second branch of the type 10 B(B), 11 } 12 13 impl<T, A, B> Either<(T, A), (T, B)> { 14 /// Splits out the homogeneous type from an either of tuples. 15 /// 16 /// This method is typically useful when combined with the `Future::select2` 17 /// combinator. split(self) -> (T, Either<A, B>)18 pub fn split(self) -> (T, Either<A, B>) { 19 match self { 20 Either::A((a, b)) => (a, Either::A(b)), 21 Either::B((a, b)) => (a, Either::B(b)), 22 } 23 } 24 } 25 26 impl<A, B> Future for Either<A, B> 27 where A: Future, 28 B: Future<Item = A::Item, Error = A::Error> 29 { 30 type Item = A::Item; 31 type Error = A::Error; 32 poll(&mut self) -> Poll<A::Item, A::Error>33 fn poll(&mut self) -> Poll<A::Item, A::Error> { 34 match *self { 35 Either::A(ref mut a) => a.poll(), 36 Either::B(ref mut b) => b.poll(), 37 } 38 } 39 } 40