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
214 downloads per month
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
, andBoth
variants- Supports arbitrary combinations of
Either
,Both
, andNeither
.
- Supports arbitrary combinations of
- Iterator and standard trait support
- (Supposed to) have compatible interfaces with
itertools
'sEither
andEitherOrBoth
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): EnablesInto
impls from and toitertools::Either
anditertools::EitherOrBoth
.
Dependencies
~230–780KB
~18K SLoC