Skip to main content

Crate mago_allocator

Crate mago_allocator 

Source
Expand description

Arena allocation for Mago.

Three bump arenas, all implementing the Arena trait:

Because all three implement Arena (and the underlying Allocator trait), allocation code is written generically over A: Arena and never needs to know which arena it was given:

fn lower<'arena, A: Arena + ?Sized>(arena: &'arena A, ast: &Ast) -> &'arena Ir<'arena> {
    arena.alloc(Ir::from(ast))
}

Allocations live as long as the borrow of the arena they came from, and are reclaimed wholesale when the arena is dropped or reset. For growable collections, use the aliases in vec, boxed, and collections, each built with its *_in(arena) constructor; to collect an iterator straight into the arena, use CollectIn (and ParallelCollectIn under the rayon feature); for an immutable string copied into the arena, use Arena::alloc_str; to deep-copy an arena-resident value into a different arena, implement CopyInto.

Each module also re-exports the items of its underlying crate (allocator_api2 for alloc, boxed, vec; hashbrown for collections), so anything not surfaced by the aliases above is still reachable.

Re-exports§

pub use arena::Arena;
pub use arena::LocalArena;
pub use arena::ScopedArena;
pub use arena::SharedArena;
pub use copy::CopyInto;
pub use iter::CollectIn;
pub use iter::FromIteratorIn;

Modules§

alloc
arena
The bump arenas and the Arena allocation trait.
boxed
collections
copy
iter
Collecting iterators directly into an arena.
prelude
Common imports for working with arenas.
vec

Macros§

format_in
Formats its arguments into an arena, returning &mut str.
vec_in
Builds an arena-allocated Vec, analogous to std::vec!.