case_iterable can be installed with cargo:
$ cargo add case_iterable
or by manually adding it to your Cargo.toml:
[dependencies]
case_iterable = "0.2.0"use case_iterable::CaseIterable;
#[derive(CaseIterable)]
enum Foo {
A,
Bar,
Chocolate,
}
for variant in Foo::all_cases() {
// Foo::A
// Foo::Bar
// Foo::Chocolate
}
// also exposes the next function used for the iterator
let x = Foo::Bar;
let y = x.next(); // Some(Foo::Chocolate)