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
41
42
43
#![no_std]
extern crate either;
use core::ops::{Deref, DerefMut};
use either::Either;
#[cfg(feature = "std_future")]
pub mod future;
#[cfg(feature = "futures01")]
mod futures01;
pub struct EitherFuture<LeftFuture, RightFuture>(Either<LeftFuture, RightFuture>);
impl<LeftFuture, RightFuture> EitherFuture<LeftFuture, RightFuture> {
pub fn left(left_future: LeftFuture) -> Self {
EitherFuture(Either::Left(left_future))
}
pub fn right(right_future: RightFuture) -> Self {
EitherFuture(Either::Right(right_future))
}
}
impl<LeftFuture, RightFuture> Deref for EitherFuture<LeftFuture, RightFuture> {
type Target = Either<LeftFuture, RightFuture>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<LeftFuture, RightFuture> DerefMut for EitherFuture<LeftFuture, RightFuture> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl<LeftFuture, RightFuture> From<Either<LeftFuture, RightFuture>> for EitherFuture<LeftFuture, RightFuture> {
fn from(either: Either<LeftFuture, RightFuture>) -> Self {
EitherFuture(either)
}
}