macro
Nested macro repetition
Nested repetitions can capture rows of differing lengths and expand each row independently. Keep the nesting of the captures in the expansion. Expected stdout (not executed): '[[1, 2], [], [9]]\n' Common mistake: Flattening a nested capture without preserving the repetition structure.
Formal Syntax & Structure
rust syntaxrust
$( [ $( $x:expr ),* ] );*Working Example
Example Snippetrust
macro_rules! rows { ($( [$($x:expr),*] );*) => {{ let data: Vec<Vec<i32>> = vec![$(vec![$($x),*]),*]; data}}; }fn main() { println!("{:?}", rows!([1, 2]; []; [9])); }