How to do it...

Follow the given steps to implement this recipe:

  1. Create a file named sample_repeat.rs, and open it in your text editor.
  2. Write the code header with the relevant information:
        //-- #########################
//-- Task: Implementing repeat
//-- Author: Vigneshwer.D
//-- Version: 1.0.0
//-- Date: 26 March 17
//-- #########################
  1. Create a macro named find_min, in which we implement repeat:
        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),+))
)
}
  1. Create a main function in which we pass multiple arguments to find_min:
        fn main() {
println!("{}", find_min!(1u32));
println!("{}", find_min!(1u32 + 2 , 2u32));
println!("{}", find_min!(5u32, 2u32 * 3, 4u32));
}

We will get the following output on the successful execution of our code:

..................Content has been hidden....................

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