Installation
[]
= "1"
Or from the terminal:
Usage
Allocate a value into the arena and get back a stable, Copy handle. The handle —
not a raw pointer — is the stable address, so a tree of nodes is wired by handle and
never tangles the borrow checker.
use ;
let mut arena = new;
let one = arena.alloc;
let two = arena.alloc;
let sum = arena.alloc; // stores handles to its children
// Child handles still resolve after the parent was allocated.
if let Some = arena.get
Back-patch a node after it exists, and walk every node without following the edges:
use Arena;
let mut arena = new;
let id = arena.alloc;
if let Some = arena.get_mut
assert_eq!;
let total: u32 = arena.iter.map.sum;
assert_eq!;
The fallible path returns a defined error instead of panicking at the u32::MAX
node ceiling:
use Arena;
let mut arena = new;
let id = arena.try_alloc?;
assert_eq!;
# Ok::
See docs/API.md for the full reference.
How it works
An Arena<T> stores its values end to end in one contiguous buffer. Allocation appends a value and returns its position as a 32-bit Id<T>; resolving one is a single indexed lookup, constant time, no search. Because values are only appended — never moved or individually freed — a handle stays valid for the life of the arena and keeps resolving to the same value through every later allocation, so nodes can reference one another by handle and the tree never moves. The whole arena is released at once when it drops, which is the allocation pattern an AST or IR wants. The handle is four bytes whatever it points at, so the space addressed by a single arena is capped at u32::MAX values; overrunning it is a defined ArenaError, never a silent wrap.
Status
v1.0.0 — stable. The full surface is in place: the typed Arena<T>, the four-byte Copy Id<T> handle, and the fallible try_alloc path, each invariant property-tested against a Vec-backed reference arena. The public API is frozen under Semantic Versioning — no breaking change before 2.0; see the ROADMAP.
Contributing
See dev/DIRECTIVES.md for engineering standards and the definition of done. Before a PR: cargo fmt --all, cargo clippy --all-targets --all-features -- -D warnings, and cargo test --all-features must be clean.