pub struct Arena<T> {
data: Vec<T>,
span_info: Vec<Span>,
}
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.
Fields§
§data: Vec<T>
Values of this arena.
span_info: Vec<Span>
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.