Created
August 28, 2013 22:21
-
-
Save pnkfelix/6372136 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| % 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