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
34
35
36
37
38
39
40
use crate::EitherFuture;
use core::future::Future;
use core::pin::Pin;
use core::task::{Context, Poll};
use either::Either;
impl<Left, Right, LeftFuture, RightFuture> Future for EitherFuture<LeftFuture, RightFuture>
where
LeftFuture: Future<Output = Left>,
RightFuture: Future<Output = Right>,
{
type Output = Either<Left, Right>;
fn poll(self: Pin<&mut Self>, context: &mut Context<'_>) -> Poll<Self::Output> {
unsafe {
match Pin::get_unchecked_mut(self).0.as_mut() {
Either::Left(left_future) => {
let left_future = Pin::new_unchecked(left_future);
match left_future.poll(context) {
Poll::Ready(left) => Poll::Ready(Either::Left(left)),
Poll::Pending => Poll::Pending,
}
}
Either::Right(right_future) => {
let right_future = Pin::new_unchecked(right_future);
match right_future.poll(context) {
Poll::Ready(right) => Poll::Ready(Either::Right(right)),
Poll::Pending => Poll::Pending,
}
}
}
}
}
}