| Crates.io | light-rc-arena |
| lib.rs | light-rc-arena |
| version | 0.1.5 |
| created_at | 2025-12-16 03:12:10.920289+00 |
| updated_at | 2025-12-17 01:06:09.747942+00 |
| description | A lightweight arena allocator that can be cloned and shared like Rc. |
| homepage | https://github.com/PsychedelicPalimpsest/light-rc-arena |
| repository | https://github.com/PsychedelicPalimpsest/light-rc-arena |
| max_upload_size | |
| id | 1987125 |
| size | 14,601 |
A Rust arena allocator focused on usability and speed.
use light_rc_arena::{Arena, ArenaRef};
use std::cell::Cell;
// Creating an arena.
type MyType = Cell<i32>;
let arena: Arena<MyType> = Arena::new();
// Allocating objects:
//
// These can be treated as &'arena MyType references. You should wrap
// them in a Cell or RefCell to mutate.
let obj1: ArenaRef<MyType, _> = arena.alloc(Cell::new(0));
let obj2: ArenaRef<MyType, _> = arena.alloc(Cell::new(1));
let obj3: ArenaRef<MyType, _> = arena.alloc(Cell::new(2));
obj1.get(); //> 0
obj2.get(); //> 1
obj3.set(-99);
assert_eq!(obj3.get(), -99); //> -99
// You can clone the Arena or ArenaRefs as much as you like, just like an Rc.
let arena2 = arena.clone();
let _ = obj1.clone();
// You can even (not recommended) get an Arena from an ArenaRef.
// In this case, it will be None if the Arena has been dropped.
let arena3: Option<Arena<MyType>> = obj1.get_arena();
// But fair warning: an ArenaRef will NOT keep the Arena alive!
// It is YOUR RESPONSIBILITY to keep the Arena alive.
drop(arena);
drop(arena2);
drop(arena3);
// let value = &*obj1; // panics
// You can test if your Arena is still alive:
let value: Option<&MyType> = obj1.try_get();
dbg!(value); //> None
Arena alive.
typed_arena crate
instead.