Struct triple_arena::Arena [−][src]
pub struct Arena<T> { /* fields omitted */ }
Expand description
An arena containing elements (that can be non-Clone
) that can be pointed
to by TriPtr
s. This is a kind of generational arena that allows deletion
and inter-arena references (even between Arena<T>
s of completely different
T
).
Implementations
impl<T> Arena<T>
[src]
impl<T> Arena<T>
[src]Note
A TriPtr
is invalid if:
- it points to a different arena than the one it is being used as an argument to
- it points to an element that has been
remove
d or has otherwise been the target of some pointer invalidation operation
pub fn new() -> Arena<T>
[src]
pub fn new() -> Arena<T>
[src]Creates a new arena that can contain elements of type T
. Note: this
function makes atomic fetches.
pub fn id(&self) -> NonZeroU64
[src]
pub fn id(&self) -> NonZeroU64
[src]Returns the unique id of this arena
pub fn try_insert(&mut self, e: T) -> Result<TriPtr, T>
[src]
pub fn try_insert(&mut self, e: T) -> Result<TriPtr, T>
[src]Tries to insert element e
into the arena without changing its
capacity.
Errors
Returns ownership of e
if there are no remaining unallocated entries
in the arena.
pub fn try_insert_with<F: FnOnce() -> T>(
&mut self,
create: F
) -> Result<TriPtr, F>
[src]
pub fn try_insert_with<F: FnOnce() -> T>(
&mut self,
create: F
) -> Result<TriPtr, F>
[src]Tries to insert the element created by create
into the arena without
changing its capacity.
Errors
Does not run create
and returns ownership if there are no remaining
unallocated entries in the arena.
pub fn insert(&mut self, e: T) -> TriPtr
[src]
pub fn insert(&mut self, e: T) -> TriPtr
[src]Inserts element e
into the arena and returns a TriPtr
to it. If more
capacity is needed, the Arena reallocates in powers of two.
pub fn get(&self, p: TriPtr) -> Option<&T>
[src]
pub fn get(&self, p: TriPtr) -> Option<&T>
[src]Returns an immutable reference to the element pointed to by p
. Returns
None
if p
is invalid.
pub fn get_mut(&mut self, p: TriPtr) -> Option<&mut T>
[src]
pub fn get_mut(&mut self, p: TriPtr) -> Option<&mut T>
[src]Returns a mutable reference to the element pointed to by p
. Returns
None
if p
is invalid.
pub fn invalidate(&mut self, p: TriPtr) -> Option<TriPtr>
[src]
pub fn invalidate(&mut self, p: TriPtr) -> Option<TriPtr>
[src]Invalidates all references to the element pointed to by p
, and returns
a new valid reference. Does no invalidation and returns None
if p
is
invalid.
pub fn replace_keep_gen(&mut self, p: TriPtr, new: T) -> Result<T, T>
[src]
pub fn replace_keep_gen(&mut self, p: TriPtr, new: T) -> Result<T, T>
[src]Replaces the element pointed to by p
with new
, returns the old
element, and keeps the internal generation counter as-is so that
previously constructed TriPtr
s to this entry are still valid.
Errors
Returns ownership of new
instead if p
is invalid
pub fn replace_update_gen(
&mut self,
p: TriPtr,
new: T
) -> Result<(TriPtr, T), T>
[src]
pub fn replace_update_gen(
&mut self,
p: TriPtr,
new: T
) -> Result<(TriPtr, T), T>
[src]Replaces the element pointed to by p
with new
, returns a tuple of
the new pointer and old element, and updates the internal generation
counter so that previously constructed TriPtr
s to this entry are
invalidated.
Errors
Does no invalidation and returns ownership of new
instead if p
is
invalid
Trait Implementations
Auto Trait Implementations
impl<T> Send for Arena<T> where
T: Send,
T: Send,
impl<T> Sync for Arena<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Arena<T> where
T: Unpin,
T: Unpin,