Skip to main content

declare_arena

Macro declare_arena 

Source
pub macro declare_arena(
    // Each of these entries becomes a `$name: TypedArena<$ty>` field in the arena.
    // This allows values of non-copy type $ty to be allocated in the arena.
    // The field names must be distinct, but have no further significance.
    $(
        $name:ident: $ty:ty,
    )*
) {
    ...
}
Expand description

Declares an Arena that can allocate values of a variety of Copy, needs_drop and !needs_drop types.

The declared arena actually contains a single DroplessArena, plus a separate TypedArena for each of the types listed in the body of the macro invocation.

Any type that is Copy can be allocated in the arena without needing to be listed explicitly. Those values will be stored in the DroplessArena.

Types that are !Copy can only be allocated if they are listed in the macro invocation. For types that are !Copy + needs_drop, values will be stored in the corresponding TypedArena and will be dropped when the arena is dropped.

As an optimization, types that are !Copy + !needs_drop will actually be stored in the DroplessArena, and the corresponding TypedArena will remain empty. This makes better use of the dropless arena’s storage blocks, while the overhead of having a few unused typed-arenas is negligible.