use std::{cell::RefCell, rc::{Rc, Weak}}; pub struct Arena { data: RefCell>>, } impl Arena { pub fn new() -> Self { Self { data: RefCell::new(vec![]), } } pub fn allocate(&self, value: T) -> Weak { let obj = Rc::new(value); self.data.borrow_mut().push(obj.clone()); Rc::downgrade(&obj) } }