Created
January 1, 2021 22:24
-
-
Save JayHelton/3cf079fe87a7ee51f4124246536f0ac7 to your computer and use it in GitHub Desktop.
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
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