8000 Change `impl Future for Either` to `Output = Either` · Issue #79 · rayon-rs/either · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Change impl Future for Either to Output = Either #79
Open
@thomaseizinger

Description

@thomaseizinger

Currently, the implementation of Future for Either requires that both Futures resolve to the same type:

either/src/lib.rs

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:

either/src/lib.rs

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)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0