#variant #enums #iterator #iteration

enumiter

An iterator through the variants in an enum

1 unstable release

Uses old Rust 2015

0.1.0 Sep 13, 2015

#33 in #iter

MIT license

4KB
75 lines

EnumIter

crates.io

Build Status

A simple iterator through the different variants in an enum.

Example

  use enumiter::{enum_iter, AllVariantsTakeNoParameters};

  #[derive(Clone, Copy, PartialEq, Eq, Debug)]
  enum Test {
    One,
    Two,
    Three,
  }

  unsafe impl AllVariantsTakeNoParameters for Test {}

  #[test]
  fn it_works() {
    let mut vals = Vec::new();

    let _ = Test::Two; // ignore dead code warning.

    for x in enum_iter(Test::One, Test::Three) {
      vals.push(x);
    }

    assert_eq!(format!("{:?}", vals), "[One, Two, Three]");
  }

Documentation

See the very thorough API Docs.

No runtime deps