1#![no_std]
2extern crate either;
18
19use core::ops::{Deref, DerefMut};
20use either::Either;
21
22#[cfg(feature = "std_future")]
23mod future;
24#[cfg(feature = "futures01")]
25mod futures01;
26#[cfg(feature = "futures03")]
27mod futures03;
28
29pub struct EitherFuture<Left, Right>(pub Either<Left, Right>);
30
31impl<Left, Right> EitherFuture<Left, Right> {
32 pub fn left(left_future: Left) -> Self {
33 EitherFuture(Either::Left(left_future))
34 }
35
36 pub fn right(right_future: Right) -> Self {
37 EitherFuture(Either::Right(right_future))
38 }
39}
40
41impl<Left, Right> Deref for EitherFuture<Left, Right> {
42 type Target = Either<Left, Right>;
43
44 fn deref(&self) -> &Self::Target {
45 &self.0
46 }
47}
48
49impl<Left, Right> DerefMut for EitherFuture<Left, Right> {
50 fn deref_mut(&mut self) -> &mut Self::Target {
51 &mut self.0
52 }
53}
54
55impl<Left, Right> From<Either<Left, Right>> for EitherFuture<Left, Right> {
56 fn from(either: Either<Left, Right>) -> Self {
57 EitherFuture(either)
58 }
59}
60
61#[cfg(not(feature = "futures03"))]
62impl<Left, Right> Into<Either<Left, Right>> for EitherFuture<Left, Right> {
63 fn into(self) -> Either<Left, Right> {
64 self.0
65 }
66}
67
68#[cfg(feature = "futures03")]
69impl<Left, Right> From<EitherFuture<Left, Right>> for Either<Left, Right> {
70 fn from(either_future: EitherFuture<Left, Right>) -> Either<Left, Right> {
71 either_future.0
72 }
73}