Skip to main content

Crate arena_lib

Crate arena_lib 

Source
Expand description

§arena-lib

TYPED MEMORY ARENAS AND SLAB ALLOCATION

arena-lib collects four allocator primitives behind a single, safe Rust surface: a generational Arena, a string Interner, a Bump arena, and the supporting Index / Symbol / Error types. Every public path is safe Rust; unsafe is internal-only, measured, and documented at the call site.

§Quick tour

use arena_lib::{Arena, Bump, Interner};

// Generational arena — stable handles, use-after-free detection.
let mut arena = Arena::new();
let alice = arena.insert("alice");
let bob = arena.insert("bob");
assert_eq!(arena.get(alice), Some(&"alice"));
let _ = arena.remove(alice);
assert_eq!(arena.get(alice), None); // stale handle, safely rejected

// Interner — O(1) equality on repeated identifiers.
let mut interner = Interner::new();
let id_a = interner.intern("user:42");
let id_b = interner.intern("user:42");
assert_eq!(id_a, id_b);

// Bump arena — fast scratch, reset in O(1).
let mut bump = Bump::with_capacity(64);
let n = bump.alloc(7_u32);
assert_eq!(*n, 7);
bump.reset();

let _ = bob;

§Modules

  • arena — generational arena and Index handle.
  • intern — string interner and Symbol handle.
  • bump — multi-chunk bump arena for short-lived scratch (no drop).
  • drop_arena — typed bump-style arena that runs destructors.
  • error — single public Error type and Result alias.
  • prelude — convenience re-exports for downstream crates.

§no_std

Disable default features (std) to compile under #![no_std]. The crate still requires alloc — it is pulled in automatically.

§License

Dual-licensed under Apache-2.0 OR MIT.

Re-exports§

pub use crate::arena::Arena;
pub use crate::arena::Index;
pub use crate::bump::Bump;
pub use crate::drop_arena::DropArena;
pub use crate::error::Error;
pub use crate::error::Result;
pub use crate::intern::Interner;
pub use crate::intern::Symbol;

Modules§

arena
Generational arena and its Index handle.
bump
Bump arena for short-lived scratch allocations.
drop_arena
Typed arena that does run destructors.
error
Error type and result alias used across the crate.
intern
String interner that hands out compact Symbol handles.
prelude
Convenience re-exports.

Constants§

VERSION
Crate version string, populated by Cargo at build time.