Crate index_arena

Crate index_arena 

Source
Expand description

A simple, id-based, heterogeneous arena allocator.

§Id-based

Uses small unique identifiers instead of references to represent allocations. This leverages the type system to statically assign every identifier to the arena it belongs to, ensuring safety without incurring runtime overhead.

Accessing individual elements is achieved via various arena methods, conceptually similar to indexing a Vec.

§Heterogeneous

Supports allocating values of all Sized types as well slices and strings. This is particularly useful for managing tree-like data structures with different node types.

§Statically guaranteed safety

The implementation leverages the power of the Rust’s type system, achieving safety with almost no runtime checks.

§No Drop

Due to the way this crate works, the arena cannot track individual allocations, so it doesn’t drop its elements, which is a necessary trade off.

§Examples

use index_arena::{Id, new_arena};

struct Even<A> {
    next: Option<Id<Odd<A>, A>>,
}

struct Odd<A> {
    next: Option<Id<Even<A>, A>>,
}

let mut arena = new_arena!();

let three = arena.alloc(Odd { next: None });
let two = arena.alloc(Even { next: Some(three) });
let one = arena.alloc(Odd { next: Some(two) });

assert_eq!(&arena[one].next, &Some(two));

Macros§

new_arena

Structs§

Arena
A simple heterogeneous arena allocator inspired by the id_arena crate.
Id
A unique identifier for an object allocated using Mrena.
RawId
SliceStorage

Enums§

SliceStorageError

Traits§

Storage
A storage backend for Arena.
SupportedType
A type that can be stored inside Arena.