Skip to main content

array_new

Macro array_new 

Source
macro_rules! array_new {
    ($e:expr, 0) => { ... };
    ($e:expr, 1) => { ... };
    ($e:expr, 2) => { ... };
    ($e:expr, 3) => { ... };
    ($e:expr, 4) => { ... };
    ($e:expr, 5) => { ... };
    ($e:expr, 6) => { ... };
    ($e:expr, 7) => { ... };
    ($e:expr, 8) => { ... };
    ($e:expr, 9) => { ... };
    ($e:expr, 10) => { ... };
    ($e:expr, 11) => { ... };
    ($e:expr, 12) => { ... };
    ($e:expr, 13) => { ... };
    ($e:expr, 14) => { ... };
    ($e:expr, 15) => { ... };
    ($e:expr, 16) => { ... };
    ($e:expr, 17) => { ... };
    ($e:expr, 18) => { ... };
    ($e:expr, 19) => { ... };
    ($e:expr, 20) => { ... };
    ($e:expr, 21) => { ... };
    ($e:expr, 22) => { ... };
    ($e:expr, 23) => { ... };
    ($e:expr, 24) => { ... };
    ($e:expr, 25) => { ... };
    ($e:expr, 26) => { ... };
    ($e:expr, 27) => { ... };
    ($e:expr, 28) => { ... };
    ($e:expr, 29) => { ... };
    ($e:expr, 30) => { ... };
    ($e:expr, 31) => { ... };
    ($e:expr, 32) => { ... };
}
Expand description

Builds [T; N] by repeating the same expression N times in the source.

Use this where [expr; N] is invalid (non-Copy T, or you need distinct evaluations of expr). Each array element is a separate copy of expr in the expansion, so array_new!(Buf::new(), 3) calls Buf::new() three times.

The first argument may be any expression valid in the surrounding context: a constructor call, a literal, a const name, or other [const]-evaluable value.

N must be a literal from 0 through 32 (inclusive). crate::BufferPool accepts 1 through 32 slots (N == 0 is only for non-pool array construction).

ยงExamples

use embedded_buffer_pool::array_new;

const ROW: [u8; 2] = [1, 2];
static GRID: [[u8; 2]; 3] = array_new!(ROW, 3);

struct Buf([u8; 4]);
impl Buf {
    const fn new() -> Self {
        Self([0; 4])
    }
}

static BUFFERS: [Buf; 2] = array_new!(Buf::new(), 2);