Rust's println! macro has a curious characteristic: there is no upper limit on the number of parameters that you can pass into it. Since regular Rust does not support arbitrary parameter ranges, it has to be a macro feature—but which? In this recipe, find out how to handle and implement parameter ranges for macros.
Using repeat for parameter ranges
How to do it...
You'll know how to use parameter ranges after these few steps:
- Run cargo new parameter-ranges --lib in Terminal (or PowerShell on Windows) and open the directory with Visual Studio Code.
- In src/lib.rs, add the following code to initialize a set in vec! style:
#![allow(unused_macros)]
macro_rules! set {
( $( $item:expr ),* ) => {
{
...