Skip to content

Instantly share code, notes, and snippets.

@JayHelton
Created January 1, 2021 22:24
Show Gist options
  • Save JayHelton/3cf079fe87a7ee51f4124246536f0ac7 to your computer and use it in GitHub Desktop.
Save JayHelton/3cf079fe87a7ee51f4124246536f0ac7 to your computer and use it in GitHub Desktop.
macro_rules! calculate {
(eval $e:expr) => {{
{
let val: usize = $e; // Force types to be integers
println!("{} = {}", stringify!{$e}, val);
}
}};
}
fn main() {
calculate! {
eval 1 + 2 // hehehe `eval` is _not_ a Rust keyword!
}
calculate! {
eval (1 + 2) * (3 / 4)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment