mirror of
https://github.com/ahgamut/rust-ape-example.git
synced 2024-10-31 21:48:49 +00:00
25 lines
503 B
Rust
25 lines
503 B
Rust
|
// ./src/macros/repeat.md
|
||
|
|
||
|
|
||
|
// `find_min!` will calculate the minimum of any number of arguments.
|
||
|
macro_rules! find_min {
|
||
|
// Base case:
|
||
|
($x:expr) => ($x);
|
||
|
// `$x` followed by at least one `$y,`
|
||
|
($x:expr, $($y:expr),+) => (
|
||
|
// Call `find_min!` on the tail `$y`
|
||
|
std::cmp::min($x, find_min!($($y),+))
|
||
|
)
|
||
|
}
|
||
|
|
||
|
fn part0() {
|
||
|
println!("{}", find_min!(1));
|
||
|
println!("{}", find_min!(1 + 2, 2));
|
||
|
println!("{}", find_min!(5, 2 * 3, 4));
|
||
|
}
|
||
|
|
||
|
pub fn main() {
|
||
|
part0();
|
||
|
}
|
||
|
|