1use crate::EitherFuture;
2use core::future::Future;
3use core::pin::Pin;
4use core::task::{Context, Poll};
5use either::Either;
6
7impl<Left, Right, LeftFuture, RightFuture> Future for EitherFuture<LeftFuture, RightFuture>
8where
9 LeftFuture: Future<Output = Left>,
10 RightFuture: Future<Output = Right>,
11{
12 type Output = Either<Left, Right>;
13
14 fn poll(self: Pin<&mut Self>, context: &mut Context<'_>) -> Poll<Self::Output> {
15 unsafe {
22 match Pin::get_unchecked_mut(self).0.as_mut() {
23 Either::Left(left_future) => {
24 let left_future = Pin::new_unchecked(left_future);
25 match left_future.poll(context) {
26 Poll::Ready(left) => Poll::Ready(Either::Left(left)),
27 Poll::Pending => Poll::Pending,
28 }
29 }
30 Either::Right(right_future) => {
31 let right_future = Pin::new_unchecked(right_future);
32 match right_future.poll(context) {
33 Poll::Ready(right) => Poll::Ready(Either::Right(right)),
34 Poll::Pending => Poll::Pending,
35 }
36 }
37 }
38 }
39 }
40}