#variant #enums #traits #case #iterator

no-std variter

Declarative macro-derivable trait for iterating over field-less enum type variants

6 releases

0.3.0 Feb 15, 2021
0.2.2 Feb 11, 2021
0.1.1 Feb 2, 2021
0.1.0 Jan 28, 2021

#1144 in Development tools

Download history 25/week @ 2024-04-01 2/week @ 2024-04-15 10/week @ 2024-04-22 1/week @ 2024-05-13 8/week @ 2024-05-27 7/week @ 2024-06-03 1/week @ 2024-06-10

73 downloads per month
Used in poker

MIT/Apache

13KB
109 lines

VarIter

Crates.io Docs.rs unsafe forbidden

variter is a Rust crate that exports some simple tools for iterating over enum types with zero or more variants that have no fields.

use variter::{VarIter, derive_var_iter};
derive_var_iter! {
    #[derive(Debug)]
    enum Greeting {
        Hello,
        Hola,
        Bonjour,
    }
}

fn main() {
    for greeting in Greeting::ALL_VARIANTS {
        println!("{:?}", greeting);
    }
}

If you're familiar with the Swift language, it's similar to using the compiler-synthesized CaseIterable protocol conformance.

See the module documentation for more information!

Usage

Add variter as a dependency in your Cargo.toml file:

[dependencies]
# ...
variter = "0.2"

Features

  • foreign_impls (default): include implementions of VarIter on stable core types.
  • std (default): if foreign_impls is turned on, VarIter implementations are included for stable std types.

no_std Support

Given the simplicity of the crate, no_std support can be toggled through the default-features = false flag in your Cargo.toml dependency table.

[dependencies]
# ...
variter = { version = "0.2", default-features = false }

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps