mirror of
https://github.com/ahgamut/rust-ape-example.git
synced 2024-05-15 01:52:42 +00:00
27 lines
405 B
Rust
27 lines
405 B
Rust
// ./src/macros/dsl.md
|
|
|
|
|
|
macro_rules! calculate {
|
|
(eval $e:expr) => {
|
|
{
|
|
let val: usize = $e; // Force types to be integers
|
|
println!("{} = {}", stringify!{$e}, val);
|
|
}
|
|
};
|
|
}
|
|
|
|
fn part0() {
|
|
calculate! {
|
|
eval 1 + 2 // hehehe `eval` is _not_ a Rust keyword!
|
|
}
|
|
|
|
calculate! {
|
|
eval (1 + 2) * (3 / 4)
|
|
}
|
|
}
|
|
|
|
pub fn main() {
|
|
part0();
|
|
}
|
|
|