use {Future, Poll, Stream}; /// Combines two different futures yielding the same item and error /// types into a single type. #[derive(Debug)] pub enum Either { /// First branch of the type A(A), /// Second branch of the type B(B), } impl Either<(T, A), (T, B)> { /// Splits out the homogeneous type from an either of tuples. /// /// This method is typically useful when combined with the `Future::select2` /// combinator. pub fn split(self) -> (T, Either) { match self { Either::A((a, b)) => (a, Either::A(b)), Either::B((a, b)) => (a, Either::B(b)), } } } impl Future for Either where A: Future, B: Future { type Item = A::Item; type Error = A::Error; fn poll(&mut self) -> Poll { match *self { Either::A(ref mut a) => a.poll(), Either::B(ref mut b) => b.poll(), } } } impl Stream for Either where A: Stream, B: Stream { type Item = A::Item; type Error = A::Error; fn poll(&mut self) -> Poll, A::Error> { match *self { Either::A(ref mut a) => a.poll(), Either::B(ref mut b) => b.poll(), } } }