Skip to content

Instantly share code, notes, and snippets.

@zokier
Last active December 28, 2015 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zokier/7498973 to your computer and use it in GitHub Desktop.
Save zokier/7498973 to your computer and use it in GitHub Desktop.
#[feature(macro_rules)];
macro_rules! enum_fmt(
($name:ident { $($member:ident),+ }) => (
enum $name {
$(
$member,
)+
}
impl std::fmt::Default for $name {
fn fmt(obj: &$name, f: &mut std::fmt::Formatter) {
let s = match *obj {
$(
$member => "$member",
)+
};
f.buf.write(s.as_bytes())
}
}
)
)
enum_fmt!(Direction {
East,
West,
North,
South
}
)
fn main() {
println!("{} {}", East, West)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment