either_future/
lib.rs

1#![no_std]
2//! `EitherFuture` is a `no_std` implementation of `Future<Output = Either<Left, Right>>` for [`Either<LeftFuture, RightFuture>`].
3//!
4//! The minimum supported rust version (MSRV) is 1.36.0 (the version where `core::future::Future` was stabilized).
5
6extern crate either;
7
8use core::ops::{Deref, DerefMut};
9use either::Either;
10
11mod future;
12
13pub struct EitherFuture<Left, Right>(pub Either<Left, Right>);
14
15impl<Left, Right> EitherFuture<Left, Right> {
16	pub fn left(left_future: Left) -> Self {
17		EitherFuture(Either::Left(left_future))
18	}
19
20	pub fn right(right_future: Right) -> Self {
21		EitherFuture(Either::Right(right_future))
22	}
23}
24
25impl<Left, Right> Deref for EitherFuture<Left, Right> {
26	type Target = Either<Left, Right>;
27
28	fn deref(&self) -> &Self::Target {
29		&self.0
30	}
31}
32
33impl<Left, Right> DerefMut for EitherFuture<Left, Right> {
34	fn deref_mut(&mut self) -> &mut Self::Target {
35		&mut self.0
36	}
37}
38
39impl<Left, Right> From<Either<Left, Right>> for EitherFuture<Left, Right> {
40	fn from(either: Either<Left, Right>) -> Self {
41		EitherFuture(either)
42	}
43}
44
45impl<Left, Right> From<EitherFuture<Left, Right>> for Either<Left, Right> {
46	fn from(either_future: EitherFuture<Left, Right>) -> Either<Left, Right> {
47		either_future.0
48	}
49}