How it works...

In this recipe, we create a macro named test, which takes two expr designators used for taking an expression as arguments and assigning it to two variables, $left and $right, where $left is assigned to the first expression and $right, to the second expression.

Inside the macros, we have two rules, which are as follows:

  • ($left:expr; and $right:expr): In this rule, we want to return a Boolean value. Here, we evaluate both the expressions and pass the values to the && operator.
  • ($left:expr; or $right:expr): In this rule, we want to return a Boolean value. Here, we evaluate both the expressions and pass the values to the || operator.
Arguments don't need to be separated by a comma and each arm must end with a semicolon.

In the main function, we call the test! macro two times with different arguments, where we have the combinations. The test!(1i32 + 1 == 2i32; and 2i32 * 2 == 4i32); combination returns the string form of the expression along with the result, which is true; test!(true; or false); similarly returns true.

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

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