Skip to main content

alloc_once

Macro alloc_once 

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

Allocate several named (possibly different-typed) values in a single bump allocation and bring each name into scope as a &mut into the arena.

Fields are separated by ;; a trailing ; is optional. The macro expands to statements, so invoke it in statement position rather than assigning its result:

alloc_once!(
    n = 1i32;
    bytes = [10u8, 20, 30];
    s = "hello";
);
*n += 41;      // n:     &mut i32
bytes[0] = 99; // bytes: &mut [u8; 3]