Skip to content

0.3.0

Compare
Choose a tag to compare
@dtolnay dtolnay released this 08 Oct 22:32
· 619 commits to master since this release
0.3.0
b058bc8
  • Extend the repetition syntax and align it more closely with the style of macro_rules! repetitions. This is a breaking change and code that used to look like #(var)* needs to be updated to #(#var)*.

Some examples of the new repetition style:

let keys = vec!["a", "b"];
let values = vec![true, false];

// "a": true, "b": false
quote! {
    #(#keys: #values),*
}
let nested = vec![
    vec!['a', 'b', 'c'],
    vec!['x', 'y', 'z'],
];

// 'a' 'b' 'c', 'x' 'y' 'z'
quote! {
    #(
        #(#nested)*
    ),*
}

In general it should feel just like macro_rules! repetitions except with # instead of $. The remaining limitations are:

  • Cannot mix repeating and non-repeating tokens at the same level. If #a is repeating (like a Vec) and #b is not, then quote! { #(#a #b)* } will not work. Ideally it would insert the same #b for each #a the way macro_rules! does but I have not figured this out yet. For now you can explicitly repeat b using std::iter::repeat.
  • Cannot repeat the same tokens more than once at the same repetition level. quote! { #a #a } continues to work as before but I have not figured out a way to support quote! { #(#a #a)* }.