Skip to content

Commit 54d73aa

Browse files
committed
add calculate
1 parent 848410c commit 54d73aa

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

examples/calculate/Cargo.toml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "calculate"
3+
version = "0.1.0"
4+
authors = ["lencx <[email protected]>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]

examples/calculate/src/main.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
macro_rules! calculate {
2+
(eval $e: expr) => {{
3+
{
4+
let val: usize = $e; // force types to be integer
5+
println!("{} = {}", stringify!($e), val);
6+
}
7+
}}
8+
}
9+
10+
fn main() {
11+
calculate! {
12+
eval 1 + 2
13+
}
14+
calculate! {
15+
eval (2 * 5) + (4 / 6)
16+
}
17+
}

0 commit comments

Comments
 (0)