Wrap Up
Using the macros is simple, coding efficient and tidy. Part of this, is the ability to have a variable number of parameters. As a Java programmer, this is something that I miss! In Rust, functions/methods don’t have this option. As you will see with Methods, this needs to be handled differently.
In this example, you’ve seen macros with:
- no parameters (
entering!()andexiting()), - a single
&str(fine!("Bit more detail.")), - a single
&strwith an interpolated variable (info!("Did some work here.\n {result}")), - multiple parameters (
warning!("Error: {}", e))
I understand that this could have been interpolated, but it is shown here as an example of the ability to emulate macros likeformat!().