[][src]Macro compact_arena::mk_arena

macro_rules! mk_arena {
    ($name:ident) => { ... };
    ($name:ident, $cap:expr) => { ... };
}

Run code using an arena. The indirection through the macro is required to safely bind the indices to the arena. The macro takes an identifier that will be bound to the &mut Arena<_, _> and an expression that will be executed within a block where the arena is instantiated. The arena will be dropped afterwards.

Examples

mk_arena!(arena);
let half = arena.add(21);
assert_eq!(42, arena[half] + arena[half]);

You can also specify an initial capacity after the arena identifier:

mk_arena!(arena, 65536);
..

The capacity will be extended automatically, so new_arena!(0) creates a valid arena with initially zero capacity that will be extended on the first add.