array

Macro array 

Source
array!() { /* proc-macro */ }
Expand description

This macro generates an array with repeated blocks of code.

§Arguments

  • n - The number of times to repeat the block.
  • ident - The identifier to use within the block.
  • block - The block of code to repeat.

§Example

use op_proc::array;
let arr = [4, 5, 6, 7, 8];
let narr = array!(3, i, {
   arr[i + 1] + 1
});
assert_eq!(narr, [6, 7, 8]);

This will expand to:

[
    {
        let i = 0;
        arr[i + 1] + 1
    },
    {
        let i = 1;
        arr[i + 1] + 1
    },
    {
        let i = 2;
        arr[i + 1] + 1
    }
]