pub struct Arena<T> { /* private fields */ }
Expand description
An arena of objects of type T
.
let mut arena = id_arena::Arena::new();
let a = arena.alloc("Albert");
assert_eq!(arena[a], "Albert");
arena[a] = "Alice";
assert_eq!(arena[a], "Alice");
Implementations
sourceimpl<T> Arena<T>
impl<T> Arena<T>
sourcepub fn new() -> Arena<T>
pub fn new() -> Arena<T>
Construct a new, empty Arena
.
let mut arena = id_arena::Arena::new();
arena.alloc(42);
sourcepub fn alloc(&mut self, item: T) -> Id<T>
pub fn alloc(&mut self, item: T) -> Id<T>
Allocate item
within this arena and return its id.
let mut arena = id_arena::Arena::new();
arena.alloc(42);
sourcepub fn get(&self, id: Id<T>) -> Option<&T>
pub fn get(&self, id: Id<T>) -> Option<&T>
Get a shared reference to the object associated with the given id
if
it exists.
If there is no object associated with id
(for example, it might
reference an object allocated within a different arena) then return
None
.
let mut arena = id_arena::Arena::new();
let id = arena.alloc(42);
assert!(arena.get(id).is_some());
let other_arena = id_arena::Arena::new();
assert!(other_arena.get(id).is_none());
sourcepub fn get_mut(&mut self, id: Id<T>) -> Option<&mut T>
pub fn get_mut(&mut self, id: Id<T>) -> Option<&mut T>
Get an exclusive reference to the object associated with the given id
if it exists.
If there is no object associated with id
(for example, it might
reference an object allocated within a different arena) then return
None
.
let mut arena = id_arena::Arena::new();
let id = arena.alloc(42);
assert!(arena.get_mut(id).is_some());
let mut other_arena = id_arena::Arena::new();
assert!(other_arena.get_mut(id).is_none());
Trait Implementations
Auto Trait Implementations
impl<T> RefUnwindSafe for Arena<T>where
T: RefUnwindSafe,
impl<T> Send for Arena<T>where
T: Send,
impl<T> Sync for Arena<T>where
T: Sync,
impl<T> Unpin for Arena<T>where
T: Unpin,
impl<T> UnwindSafe for Arena<T>where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more