iter_variants

Crates.ioiter_variants
lib.rsiter_variants
version0.2.0
created_at2025-04-07 17:16:42.390807+00
updated_at2025-04-15 10:07:29.976457+00
descriptionA way to iterate over all variants of a rust struct/enum
homepagehttps://github.com/jonathandw743/iter_variants
repositoryhttps://github.com/jonathandw743/iter_variants
max_upload_size
id1624481
size16,833
Jonathan Wilson (jonathandw743)

documentation

README

iter_variants

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.

Commit count: 52

cargo fmt