`exhaust` v0.2.5 — iterate over every value of a type
⚓ Rust 📅 2026-03-14 👤 surdeus 👁️ 4exhaust is a small trait-and-derive-macro library providing the Exhaust trait, which allow iterating over all values of a given type (both std types and your own structs and enums via #[derive(Exhaust)]).
use exhaust::Exhaust;
#[derive(PartialEq, Debug, Exhaust)]
struct Foo {
a: bool,
b: Bar,
}
#[derive(PartialEq, Debug, Exhaust)]
enum Bar {
One,
Two(bool),
}
assert_eq!(
Foo::exhaust().collect::<Vec<Foo>>(),
vec![
Foo { a: false, b: Bar::One },
Foo { a: false, b: Bar::Two(false) },
Foo { a: false, b: Bar::Two(true) },
Foo { a: true, b: Bar::One },
Foo { a: true, b: Bar::Two(false) },
Foo { a: true, b: Bar::Two(true) },
],
);
exhaust is useful for:
- testing functions of
enums and small structs with 100% coverage, - building lookup tables,
- brute force searches,
- and anything else where you want to compute or initialize something for every possible case specified by a type.
Today I released v0.2.5, which reduces code size and memory usage, and offers the factory_is_self option for deriving less code when possible. It’s not a flashy release with powerful new features, but I think that reflects that exhaust is a reliable library for its one purpose, so I thought it would be a good time to tell you about it for the first time. (Why not 1.0 yet?)
1 post - 1 participant
🏷️ Rust_feed