pub struct Arena<T> { /* private fields */ }Expand description
A typed arena that provides reference-counted pointers to its underlying objects.
Implementations§
Source§impl<T> Arena<T>
impl<T> Arena<T>
Sourcepub fn with_capacity(n: usize) -> Arena<T>
pub fn with_capacity(n: usize) -> Arena<T>
Create a new arena with a known initial capacity.
Sourcepub fn alloc(&self, value: T) -> Rc<T>
pub fn alloc(&self, value: T) -> Rc<T>
Store an object in the arena, returning a reference counted pointer to it.
use rc_arena::Arena;
let arena = Arena::new();
let foo = arena.alloc([0; 256]);
let bar = arena.alloc([1; 256]);
let baz = bar.clone();
assert_eq!(foo[0], 0);
assert_eq!(bar[0], 1);
assert_eq!(baz[0], 1);Sourcepub fn each<F: for<'a> FnMut(&'a Rc<T>)>(&self, f: F)
pub fn each<F: for<'a> FnMut(&'a Rc<T>)>(&self, f: F)
Iterate over the objects in the arena, accepting a closure which will be passed a reference to the Rc of the object. This may be deprecated in favor of a (safe) iterator API in the future.
This will always iterate in the order that the objects were allocated.
use rc_arena::Arena;
let arena = Arena::new();
arena.alloc("Hello,");
arena.alloc(" ");
arena.alloc("world!\n");
arena.each(|obj| {
print!("{}", obj);
});Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Arena<T>
impl<T> !RefUnwindSafe for Arena<T>
impl<T> !Send for Arena<T>
impl<T> !Sync for Arena<T>
impl<T> Unpin for Arena<T>
impl<T> !UnwindSafe for Arena<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more