#enums #either

no-std quither

A flexible enum-based utility for representing values that may be on the left, right, neither, or both sides

4 releases (breaking)

Uses new Rust 2024

new 0.4.0 May 12, 2025
0.3.0 May 11, 2025
0.2.0 May 11, 2025
0.1.0 May 10, 2025

#367 in Data structures

Download history 214/week @ 2025-05-06

214 downloads per month

Apache-2.0

110KB
2K SLoC

quither

A flexible enum-based utility for representing values that may be on the left, right, neither, or both sides.

Highlights

  • Provides a generic enum type supporting Left, Right, Neither, and Both variants
    • Supports arbitrary combinations of Either, Both, and Neither.
  • Iterator and standard trait support
  • (Supposed to) have compatible interfaces with itertools's Either and EitherOrBoth types.
  • No-std compatible, can be build without std features.

Example

use quither::{Quither, NeitherOrBoth};

// You can create values with any combination of variants:
let left = Quither::Left(1);
let right = Quither::Right(2);
let both = Quither::Both(1, 2);
let neither = Quither::Neither;

// Pattern matching on Quither
match both {
    Quither::Left(l) => println!("Left: {}", l),
    Quither::Right(r) => println!("Right: {}", r),
    Quither::Both(l, r) => println!("Both: {}, {}", l, r),
    Quither::Neither => println!("Neither"),
}

// You can also convert between different variant sets using TryInto:
// For example, convert a Quither to a type with only Neither and Both variants
let neither_or_both: NeitherOrBoth<_, _> = both.try_into().unwrap();

// Pattern matching works as usual
match neither_or_both {
    NeitherOrBoth::Both(l, r) => println!("Both: {}, {}", l, r),
    NeitherOrBoth::Neither => println!("Neither"),
}

Crate Features

  • use_std (default: enabled): Enables implementations for std types (e.g., Read, BufRead)
  • itertools (default: disabled): Enables Into impls from and to itertools::Either and itertools::EitherOrBoth.

Dependencies

~230–780KB
~18K SLoC