Created
September 13, 2014 23:02
-
-
Save domluna/49dcb78d030cce00cced to your computer and use it in GitHub Desktop.
Example of a macro in rust
This file contains 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
#![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