mirror of
https://github.com/ahgamut/rust-ape-example.git
synced 2024-06-01 02:08:06 +00:00
d976dc883b
via panflute and https://github.com/rust-lang/rust-by-example
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();
|
|
}
|
|
|