Module std::arena

Generational-index slotmap (Arena<T>).

An Arena<T> is an owned, Vec-backed store that hands out stable, generation-checked handles (Key<T>) instead of pointers. An arena owns mutable identity state and cannot be cloned; its keys remain plain values. Insertion and removal use O(1) slot bookkeeping; returning an owned T follows the value model and may additionally cost O(size of T). A key keeps working across unrelated mutations and fails closed once the value it named is removed, even if the slot is later reused. This is the primitive for stable references under the value model: graph/tree node stores, ECS-style component tables, interner back-stores, and handle registries.

Examples

import std::arena;

fn main() {
    let store: arena.Arena<string> = arena.new();
    let key = store.insert("hello");
    println(store.get(key).unwrap());   // hello
    store.remove(key);
    println(store.get(key).is_none());  // true
}

Contents

Functions

Function new

pub fn new() -> Arena<T>

Create a new, empty arena.

The element type is inferred from the binding, e.g. let store: arena.Arena<i64> = arena.new();.

Types

Struct Key

A stable, generation-checked handle into an Arena<T>.

Returned by insert; pass it to get, remove, or contains. A key stays valid until its value is removed. Once removed, the key fails closed forever โ€” get returns None even after the slot is reused by a later insert, because that reuse issues a fresh key with a higher generation. The T tag prevents cross-element-type use, and the instance identity prevents an independently-constructed same-typed arena from accepting an issued key.

Fields

arena_id: i64
index: i64
generation: i64

Struct Arena

A generational-index slotmap with O(1) slot bookkeeping.

Construct with arena.new(). Values are owned by the arena; accessors return Option<T> copies under the value model, never references. An arena is non-cloneable because forking its identity state could issue ambiguous keys.

Fields

clone_guard: ArenaCloneGuard
arena_id: i64
generation_counter: Vec<i64>
slots: Vec<Slot<T>>
free: Vec<i64>