Skip to content

Instantly share code, notes, and snippets.

@pnkfelix
Created August 28, 2013 22:21
Show Gist options
  • Save pnkfelix/6372136 to your computer and use it in GitHub Desktop.
Save pnkfelix/6372136 to your computer and use it in GitHub Desktop.
enum Foo { a, b, c }
static all_Foo : &'static [Foo] = &'static [a, b, c];
fn iterFoo() -> std::vec::VecIterator<Foo> { all_Foo.iter() }
macro_rules! enum_with_iter (
($M:ident $E:ident $F:ident { $($V:ident),* }) =>
( mod $M {
use std;
pub enum $E { $($V),* }
static all_E : &'static [$E] = &'static [$($V),*];
pub fn $F() -> std::vec::VecIterator<$E> { all_E.iter() }
}
))
enum_with_iter!(B Bar iterBar { x, y, z })
fn main() {
use B::*;
println("Hello Foo");
for f in iterFoo() {
print(fmt!("%? ", *f));
}
println("Hello Bar");
for g in iterBar() {
print(fmt!("%? ", *g));
}
println("End of World");
}
% rustc enumiter.rs && ./enumiter
warning: no debug symbols in executable (-arch x86_64)
Hello Foo
a b c Hello Bar
x y z End of World
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment