[][src]Macro compact_arena::in_arena

macro_rules! in_arena {
    ($arena:ident, $e:expr) => { ... };
    ($arena:ident / $cap:expr, $e: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

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

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

in_arena!(arena / 65536, {
    ..
});