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, andBothvariants- Supports arbitrary combinations of
Either,Both, andNeither.
- Supports arbitrary combinations of
- Iterator and standard trait support
- More and clearer iterator types than
itertools'sEitherandEitherOrBothtypes.
- More and clearer iterator types than
- (Supposed to) have compatible interfaces with
itertools'sEitherandEitherOrBothtypes. - Fallible
mapmethods, liketry_map()ortry_map_left(). - Convert between each variant types.
- Expanding conversion like
EithertoEitherOrBothis infallible. - Contracting conversion like
EitherOrBothtoEitheris fallible, where the error type returns the remaining variant type (Bothin this case).
- Expanding conversion like
- No-std compatible, can be build without
stdfeatures. - A bonus feature: Supports the transposition of
Result<impl IntoIterator, E>type intoimpl Iterator<Item = Result<T, E>>type.
Example
use ;
// You can create values with any combination of variants:
let left: = Left;
let right: = Right;
let both: = Both;
let neither = Neither;
let left2: = Left;
// Pattern matching on Quither
match both
// You can convert the type to a "larger" type
let left2_in_quither: = left2.into;
// You can also convert into a "smaller" type with fallible conversion.
// For example, convert a Quither to a type with only Neither and Both variants
let neither_or_both: = both.try_into.unwrap;
// Pattern matching works as usual
match neither_or_both
Crate Features
use_std(default: enabled): Enables implementations for std types (e.g., Read, BufRead)itertools(default: disabled): EnablesIntoimpls from and toitertools::Eitheranditertools::EitherOrBoth.