Re: [PATCH v3 19/19] rust: io: implement `Io` for `Either`
From: Miguel Ojeda
Date: Thu Jun 11 2026 - 01:31:47 EST
On Mon, Jun 8, 2026 at 9:59 PM Gary Guo <gary@xxxxxxxxxxx> wrote:
>
> +/// General purpose sum type with two cases.
> +#[derive(Clone, Copy)]
> +pub enum Either<L, R> {
> + /// A value of type `L`.
> + Left(L),
> + /// A value of type `R`.
> + Right(R),
> +}
[ A summary of what I mentioned in the call yesterday so that others
can see it too. ]
We had `Either` in the past and we ended up removing it in commit
28753212e0f9 ("rust: types: remove `Either<L, R>`"):
This enum is not used. Additionally, using it would result in poor
ergonomics, because in order to do any operation on a value it has to be
matched first. Our version of `Either` also doesn't provide any helper
methods making it even more difficult to use.
The alternative of creating a custom enum for the concrete use-case also
is much better for ergonomics. As one can provide functions on the type
directly and users don't need to match the value manually.
We also wanted to try to get developers to provide more concrete
enums/names for their use cases, instead of using `Either` whenever
they may have two symmetrical values.
Anyway, if we want to re-introduce it, we should likely add what we
had when we removed it (possibly just reverting the commit), which
included examples etc.; and probably add in its docs some guidance on
when (and when not) to use it.
Cc Benno.
Cheers,
Miguel