pub struct UniqueArena<T> {
set: FastIndexSet<T>,
span_info: Vec<Span>,
}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.
Fields§
§set: FastIndexSet<T>§span_info: Vec<Span>Spans for the elements, indexed by handle.
The length of this vector is always equal to set.len(). FastIndexSet
promises that its elements “are indexed in a compact range, without
holes in the range 0..set.len()”, so we can always use the indices
returned by insertion as indices into this vector.
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.
Trait Implementations§
Source§impl<'a, T> Arbitrary<'a> for UniqueArena<T>
impl<'a, T> Arbitrary<'a> for UniqueArena<T>
Source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Self from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self>
Self from the entirety of the given
unstructured data. Read moreSource§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<'de, T> Deserialize<'de> for UniqueArena<T>
impl<'de, T> Deserialize<'de> for UniqueArena<T>
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<T> Index<Handle<T>> for UniqueArena<T>
impl<T> Index<Handle<T>> for UniqueArena<T>
Source§impl<T> Serialize for UniqueArena<T>
impl<T> Serialize for UniqueArena<T>
Source§impl<T> SpanProvider<T> for UniqueArena<T>
impl<T> SpanProvider<T> for UniqueArena<T>
fn get_span(&self, handle: Handle<T>) -> Span
fn get_span_context(&self, handle: Handle<T>) -> SpanContext
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.