| Crates.io | iter_variants |
| lib.rs | iter_variants |
| version | 0.2.0 |
| created_at | 2025-04-07 17:16:42.390807+00 |
| updated_at | 2025-04-15 10:07:29.976457+00 |
| description | A way to iterate over all variants of a rust struct/enum |
| homepage | https://github.com/jonathandw743/iter_variants |
| repository | https://github.com/jonathandw743/iter_variants |
| max_upload_size | |
| id | 1624481 |
| size | 16,833 |
cargo add iter_variants
Provides a trait IterVariants with one method iter_variants that takes one argument, an FnMut that is called on all variants of the given struct/enum. For exampe, bool::iter_variants(f) would call f(false) and f(true).
This is different to strum::EnumIter because this will iterate over all variants of contained data to any depth, and also works for structs, tuples, primitives and many core types.
There is a corresponding derive macro that implements IterVariants for enums and structs where all fields are either unit or only contain types that also implement IterVariants.
This crate is no_std.
Thanks to @A4-Tacks for work on generics and implementations for many core types.