pub struct Arena<T> { /* private fields */ }
Expand description
An arena holding some kind of component (e.g., type, constant, instruction, etc.) that can be referenced.
Adding new items to the arena produces a strongly-typed Handle
.
The arena can be indexed using the given handle to obtain
a reference to the stored item.
Implementations§
Source§impl<T> Arena<T>
impl<T> Arena<T>
Sourcepub fn into_inner(self) -> Vec<T>
pub fn into_inner(self) -> Vec<T>
Extracts the inner vector.
Sourcepub fn iter(&self) -> impl DoubleEndedIterator<Item = (Handle<T>, &T)>
pub fn iter(&self) -> impl DoubleEndedIterator<Item = (Handle<T>, &T)>
Returns an iterator over the items stored in this arena, returning both the item’s handle and a reference to it.
Sourcepub fn drain(&mut self) -> impl DoubleEndedIterator<Item = (Handle<T>, T, Span)>
pub fn drain(&mut self) -> impl DoubleEndedIterator<Item = (Handle<T>, T, Span)>
Drains the arena, returning an iterator over the items stored.
Sourcepub fn iter_mut(
&mut self,
) -> impl DoubleEndedIterator<Item = (Handle<T>, &mut T)>
pub fn iter_mut( &mut self, ) -> impl DoubleEndedIterator<Item = (Handle<T>, &mut T)>
Returns a iterator over the items stored in this arena, returning both the item’s handle and a mutable reference to it.
Sourcepub fn append(&mut self, value: T, span: Span) -> Handle<T>
pub fn append(&mut self, value: T, span: Span) -> Handle<T>
Adds a new value to the arena, returning a typed handle.
Sourcepub fn fetch_if<F: Fn(&T) -> bool>(&self, fun: F) -> Option<Handle<T>>
pub fn fetch_if<F: Fn(&T) -> bool>(&self, fun: F) -> Option<Handle<T>>
Fetch a handle to an existing type.
Sourcepub fn fetch_if_or_append<F: Fn(&T, &T) -> bool>(
&mut self,
value: T,
span: Span,
fun: F,
) -> Handle<T>
pub fn fetch_if_or_append<F: Fn(&T, &T) -> bool>( &mut self, value: T, span: Span, fun: F, ) -> Handle<T>
Adds a value with a custom check for uniqueness: returns a handle pointing to an existing element if the check succeeds, or adds a new element otherwise.
Sourcepub fn fetch_or_append(&mut self, value: T, span: Span) -> Handle<T>where
T: PartialEq,
pub fn fetch_or_append(&mut self, value: T, span: Span) -> Handle<T>where
T: PartialEq,
Adds a value with a check for uniqueness, where the check is plain comparison.
pub fn try_get(&self, handle: Handle<T>) -> Result<&T, BadHandle>
Sourcepub fn get_mut(&mut self, handle: Handle<T>) -> &mut T
pub fn get_mut(&mut self, handle: Handle<T>) -> &mut T
Get a mutable reference to an element in the arena.
Sourcepub fn range_from(&self, old_length: usize) -> Range<T> ⓘ
pub fn range_from(&self, old_length: usize) -> Range<T> ⓘ
Get the range of handles from a particular number of elements to the end.
pub fn get_span(&self, handle: Handle<T>) -> Span
Sourcepub fn check_contains_handle(&self, handle: Handle<T>) -> Result<(), BadHandle>
pub fn check_contains_handle(&self, handle: Handle<T>) -> Result<(), BadHandle>
Assert that handle
is valid for this arena.
Sourcepub fn check_contains_range(
&self,
range: &Range<T>,
) -> Result<(), BadRangeError>
pub fn check_contains_range( &self, range: &Range<T>, ) -> Result<(), BadRangeError>
Assert that range
is valid for this arena.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Arena<T>
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§
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)