either-both 1.0.0

An enum similar to the well-known `Either`, but with a `Both` variant
Documentation
  • Coverage
  • 82.05%
    64 out of 78 items documented47 out of 74 items with examples
  • Size
  • Source code size: 80.67 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.17 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 7s Average build duration of successful builds.
  • all releases: 7s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • spenserblack/either-both
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • spenserblack

either-both

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.

A common use case could be replacing the type (Option<L>, Option<R>) where the (None, None) variant is impossible.

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> {
        let either = match (self.0.next(), self.1.next()) {
            (Some(a), Some(b)) => Both(a, b),
            (Some(a), None) => Left(a),
            (None, Some(b)) => Right(b),
            (None, None) => return None,
        };
        Some(either)
    }
}