mirror of
https://github.com/ahgamut/rust-ape-example.git
synced 2024-11-21 23:41:00 +00:00
32 lines
796 B
Rust
32 lines
796 B
Rust
// ./src/macros/overload.md
|
|
|
|
|
|
// `test!` will compare `$left` and `$right`
|
|
// in different ways depending on how you invoke it:
|
|
macro_rules! test {
|
|
// Arguments don't need to be separated by a comma.
|
|
// Any template can be used!
|
|
($left:expr; and $right:expr) => {
|
|
println!("{:?} and {:?} is {:?}",
|
|
stringify!($left),
|
|
stringify!($right),
|
|
$left && $right)
|
|
};
|
|
// ^ each arm must end with a semicolon.
|
|
($left:expr; or $right:expr) => {
|
|
println!("{:?} or {:?} is {:?}",
|
|
stringify!($left),
|
|
stringify!($right),
|
|
$left || $right)
|
|
};
|
|
}
|
|
|
|
fn part0() {
|
|
test!(1i32 + 1 == 2i32; and 2i32 * 2 == 4i32);
|
|
test!(true; or false);
|
|
}
|
|
|
|
pub fn main() {
|
|
part0();
|
|
}
|
|
|