futures_core/future/
either.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use {task, Future, Poll, Stream};

use either::Either;

impl<A, B> Future for Either<A, B>
    where A: Future,
          B: Future<Item = A::Item, Error = A::Error>
{
    type Item = A::Item;
    type Error = A::Error;

    fn poll(&mut self, cx: &mut task::Context) -> Poll<A::Item, A::Error> {
        match *self {
            Either::Left(ref mut a) => a.poll(cx),
            Either::Right(ref mut b) => b.poll(cx),
        }
    }
}

impl<A, B> Stream for Either<A, B>
    where A: Stream,
          B: Stream<Item = A::Item, Error = A::Error>
{
    type Item = A::Item;
    type Error = A::Error;

    fn poll_next(&mut self, cx: &mut task::Context) -> Poll<Option<A::Item>, A::Error> {
        match *self {
            Either::Left(ref mut a) => a.poll_next(cx),
            Either::Right(ref mut b) => b.poll_next(cx),
        }
    }
}