How to do it...

  1. In the src/bin folder, create a file called variadic.rs

  2. Add the following code and run it with cargo run --bin variadic:

1   macro_rules! multiply {
2 // Edge case
3 ( $last:expr ) => { $last };
4
5 ( $head:expr, $($tail:expr), +) => {
6 // Recursive call
7 $head * multiply!($($tail),+)
8 };
9 }
10
11 fn main() {
12 // You can call multiply! with
13 // as many parameters as you want
14 let val = multiply!(2, 4, 8);
15 println!("2*4*8 = {}", val)
16 }
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.245.233