-
Notifications
You must be signed in to change notification settings - Fork 71
Open
Description
Currently, the implementation of Future for Either requires that both Futures resolve to the same type:
Lines 1127 to 1141 in af9f5fb
| /// `Either<L, R>` is a future if both `L` and `R` are futures. | |
| impl<L, R> Future for Either<L, R> | |
| where | |
| L: Future, | |
| R: Future<Output = L::Output>, | |
| { | |
| type Output = L::Output; | |
| fn poll( | |
| self: Pin<&mut Self>, | |
| cx: &mut core::task::Context<'_>, | |
| ) -> core::task::Poll<Self::Output> { | |
| for_both!(self.as_pin_mut(), inner => inner.poll(cx)) | |
| } | |
| } |
This limits, which kinds of Futures can be expressed using Either. It would be more useful to set the Output type to Either<A::Output, B::Output>. This is an API breaking change.
The original behaviour can be restored using the Either::into_inner function. In case both Futures, A and B have the same Output, the into_inner function can be used to "unwrap" the Either:
Lines 916 to 930 in af9f5fb
| impl<T> Either<T, T> { | |
| /// Extract the value of an either over two equivalent types. | |
| /// | |
| /// ``` | |
| /// use either::*; | |
| /// | |
| /// let left: Either<_, u32> = Left(123); | |
| /// assert_eq!(left.into_inner(), 123); | |
| /// | |
| /// let right: Either<u32, _> = Right(123); | |
| /// assert_eq!(right.into_inner(), 123); | |
| /// ``` | |
| pub fn into_inner(self) -> T { | |
| for_both!(self, inner => inner) | |
| } |
a1phyr
Metadata
Metadata
Assignees
Labels
No labels