Skip to content

Instantly share code, notes, and snippets.

@domluna
Created September 13, 2014 23:02
Show Gist options
  • Save domluna/49dcb78d030cce00cced to your computer and use it in GitHub Desktop.
Save domluna/49dcb78d030cce00cced to your computer and use it in GitHub Desktop.
Example of a macro in rust
#![feature(macro_rules)]
macro_rules! loop_x {
($e: expr) => {
// $e will not interact with this 'x
// refers to the 'x in the outside loop
'x: loop {
println!("Hello!");
$e
}
}
}
fn main() {
'x: loop {
// the 'x passed into loop_x! refers to
// the one that defines this current loop
loop_x!(break 'x);
println!("This will never print!");
println!("Another thing that will never print!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment