Skip to content

Instantly share code, notes, and snippets.

@AndrewGaspar
AndrewGaspar / global_arena.rs
Created April 30, 2020 15:14
Global Arena Rust
use std::cell::RefCell;
// `generational_arena` is a special type of arena that allows elements to be recycled, and the
// handles allocated from the arena do not hold a borrow on the arena. The handles are later used to
// retrieve concrete borrows on the arena temporarily. The check for live-ness is essentially
// performed at runtime, rather than being checked by the borrow checker.
use generational_arena::{Arena, Index};
// Allocate `ARENA` at global/thread scope. The arena is wrapped in a RefCell so we can get
// runtime-checked mutable borrows of the arena.