actix/fut/future/
either.rs

1use std::{
2    pin::Pin,
3    task::{Context, Poll},
4};
5
6use futures_util::future::Either;
7
8use crate::{actor::Actor, fut::ActorFuture};
9
10impl<A, B, Act> ActorFuture<Act> for Either<A, B>
11where
12    A: ActorFuture<Act>,
13    B: ActorFuture<Act, Output = A::Output>,
14    Act: Actor,
15{
16    type Output = A::Output;
17
18    fn poll(
19        self: Pin<&mut Self>,
20        act: &mut Act,
21        ctx: &mut Act::Context,
22        task: &mut Context<'_>,
23    ) -> Poll<A::Output> {
24        // SAFETY:
25        //
26        // Copied from futures_util::future::Either::project method.
27        // This is used to expose this method to public.
28        // It has the same safety as the private one.
29        let this = unsafe {
30            match self.get_unchecked_mut() {
31                Either::Left(a) => Either::Left(Pin::new_unchecked(a)),
32                Either::Right(b) => Either::Right(Pin::new_unchecked(b)),
33            }
34        };
35
36        match this {
37            Either::Left(left) => left.poll(act, ctx, task),
38            Either::Right(right) => right.poll(act, ctx, task),
39        }
40    }
41}