Skip to main content

Crate either_both

Crate either_both 

Source
Expand description

This crate is intended to be similar to either, but also cover the “both” variant.

This crate was inspired by wanting to implement a method similar to Iterator::zip that continues until both zipped iterators are exhausted.

§Usage

It’s recommended to use the prelude, which brings into scope Either<L, R>, and also its variants:

  • Left
  • Right
  • Both
use either_both::prelude::*;

// Just like how Option's and Result's variants are often used without the prefix,
// you can now use Left, Right, and Both without prefixing with "Either::"
const CHOICES: [Either<bool, u8>;3] = [Left(true), Right(1), Both(false, 0)];

§Example

use either_both::prelude::*;

pub struct ZipToEnd<A: Iterator, B: Iterator>(A, B);

impl<A: Iterator, B: Iterator> Iterator for ZipToEnd<A, B> {
    type Item = Either<<A as Iterator>::Item, <B as Iterator>::Item>;

    fn next(&mut self) -> Option<Self::Item> {
        Either::from_options(self.0.next(), self.1.next())
    }
}

Re-exports§

pub use Either::Both;
pub use Either::Left;
pub use Either::Right;

Modules§

prelude
The recommended types and values from this library to bring into scope.

Structs§

Iter
The iterator for Either.

Enums§

Either
The main enum, with variants Left, Right, and Both.

Functions§

neither
Always returns None, to represent when neither the left nor right value are present.

Type Aliases§

MaybeEither
A shortcut to represent the possibility of neither left nor right values existing by wrapping the Either<L, R> in an Option.