pub struct UniqueArena<T> { /* private fields */ }Expand description
An arena whose elements are guaranteed to be unique.
A UniqueArena holds a set of unique values of type T, each with an
associated Span. Inserting a value returns a Handle<T>, which can be
used to index the UniqueArena and obtain shared access to the T element.
Access via a Handle is an array lookup - no hash lookup is necessary.
The element type must implement Eq and Hash. Insertions of equivalent
elements, according to Eq, all return the same Handle.
Once inserted, elements generally may not be mutated, although a replace
method exists to support rare cases.
UniqueArena is similar to Arena: If Arena is vector-like,
UniqueArena is HashSet-like.
Implementations§
Source§impl<T> UniqueArena<T>
impl<T> UniqueArena<T>
Source§impl<T: Eq + Hash> UniqueArena<T>
impl<T: Eq + Hash> UniqueArena<T>
Sourcepub fn iter(
&self,
) -> impl DoubleEndedIterator<Item = (Handle<T>, &T)> + ExactSizeIterator
pub fn iter( &self, ) -> impl DoubleEndedIterator<Item = (Handle<T>, &T)> + ExactSizeIterator
Returns an iterator over the items stored in this arena, returning both the item’s handle and a reference to it.
Sourcepub fn insert(&mut self, value: T, span: Span) -> Handle<T>
pub fn insert(&mut self, value: T, span: Span) -> Handle<T>
Insert a new value into the arena.
Return a Handle<T>, which can be used to index this arena to get a
shared reference to the element.
If this arena already contains an element that is Eq to value,
return a Handle to the existing element, and drop value.
If value is inserted into the arena, associate span with
it. An element’s span can be retrieved with the get_span
method.
Sourcepub fn replace(&mut self, old: Handle<T>, new: T)
pub fn replace(&mut self, old: Handle<T>, new: T)
Replace an old value with a new value.
§Panics
- if the old value is not in the arena
- if the new value already exists in the arena
Sourcepub fn get(&self, value: &T) -> Option<Handle<T>>
pub fn get(&self, value: &T) -> Option<Handle<T>>
Return this arena’s handle for value, if present.
If this arena already contains an element equal to value,
return its handle. Otherwise, return None.
Sourcepub fn get_handle(&self, handle: Handle<T>) -> Result<&T, BadHandle>
pub fn get_handle(&self, handle: Handle<T>) -> Result<&T, BadHandle>
Return this arena’s value at handle, if that is a valid handle.
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.
Trait Implementations§
Source§impl<T: Clone> Clone for UniqueArena<T>
impl<T: Clone> Clone for UniqueArena<T>
Source§fn clone(&self) -> UniqueArena<T>
fn clone(&self) -> UniqueArena<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T> Default for UniqueArena<T>
impl<T> Default for UniqueArena<T>
Source§impl<T> Index<Handle<T>> for UniqueArena<T>
impl<T> Index<Handle<T>> for UniqueArena<T>
Source§impl TypeContext for UniqueArena<Type>
Format types as WGSL based on a UniqueArena<Type>.
impl TypeContext for UniqueArena<Type>
Format types as WGSL based on a UniqueArena<Type>.
This is probably only good enough for logging:
-
It does not apply any kind of
Namerrenamings. -
It generates invalid WGSL for anonymous struct types.
-
It doesn’t write override-sized arrays properly.
Source§fn type_name(&self, handle: Handle<Type>) -> &str
fn type_name(&self, handle: Handle<Type>) -> &str
handle.Source§fn write_unnamed_struct<W: Write>(
&self,
inner: &TypeInner,
out: &mut W,
) -> Result
fn write_unnamed_struct<W: Write>( &self, inner: &TypeInner, out: &mut W, ) -> Result
TypeInner::Struct for which we are unable to find a name. Read moreSource§fn write_override<W: Write>(
&self,
handle: Handle<Override>,
out: &mut W,
) -> Result
fn write_override<W: Write>( &self, handle: Handle<Override>, out: &mut W, ) -> Result
override to out.Source§fn write_type<W: Write>(&self, handle: Handle<Type>, out: &mut W) -> Result
fn write_type<W: Write>(&self, handle: Handle<Type>, out: &mut W) -> Result
ty as it would appear in a value’s declaration. Read moreSource§fn write_scalar<W: Write>(&self, scalar: Scalar, out: &mut W) -> Result
fn write_scalar<W: Write>(&self, scalar: Scalar, out: &mut W) -> Result
Scalar scalar as a WGSL type.Source§fn write_type_resolution<W: Write>(
&self,
resolution: &TypeResolution,
out: &mut W,
) -> Result
fn write_type_resolution<W: Write>( &self, resolution: &TypeResolution, out: &mut W, ) -> Result
TypeResolution resolution as a WGSL type.