Crates.io | enumiter |
lib.rs | enumiter |
version | 0.1.0 |
source | src |
created_at | 2015-09-13 23:17:03.260974 |
updated_at | 2015-12-11 23:58:51.47213 |
description | An iterator through the variants in an enum. |
homepage | https://github.com/cgaebel/enumiter |
repository | https://github.com/cgaebel/enumiter |
max_upload_size | |
id | 3043 |
size | 4,504 |
A simple iterator through the different variants in an enum.
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]");
}
See the very thorough API Docs.