Struct wgpu::naga::UniqueArena
source · pub struct UniqueArena<T> { /* private fields */ }
wgpu_core
or naga
only.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 may not be mutated.
UniqueArena
is similar to Arena
: If Arena
is vector-like,
UniqueArena
is HashSet
-like.
Implementations§
source§impl<T> UniqueArena<T>
impl<T> UniqueArena<T>
sourcepub fn new() -> UniqueArena<T>
Available on wgpu_core
only.
pub fn new() -> UniqueArena<T>
wgpu_core
only.Create a new arena with no initial capacity allocated.
sourcepub fn len(&self) -> usize
Available on wgpu_core
only.
pub fn len(&self) -> usize
wgpu_core
only.Return the current number of items stored in this arena.
source§impl<T> UniqueArena<T>
impl<T> UniqueArena<T>
sourcepub fn iter(&self) -> impl DoubleEndedIterator
Available on wgpu_core
only.
pub fn iter(&self) -> impl DoubleEndedIterator
wgpu_core
only.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>
Available on wgpu_core
only.
pub fn insert(&mut self, value: T, span: Span) -> Handle<T>
wgpu_core
only.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)
Available on wgpu_core
only.
pub fn replace(&mut self, old: Handle<T>, new: T)
wgpu_core
only.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>>
Available on wgpu_core
only.
pub fn get(&self, value: &T) -> Option<Handle<T>>
wgpu_core
only.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>
Available on wgpu_core
only.
pub fn get_handle(&self, handle: Handle<T>) -> Result<&T, BadHandle>
wgpu_core
only.Return this arena’s value at handle
, if that is a valid handle.
sourcepub fn check_contains_handle(&self, handle: Handle<T>) -> Result<(), BadHandle>
Available on wgpu_core
only.
pub fn check_contains_handle(&self, handle: Handle<T>) -> Result<(), BadHandle>
wgpu_core
only.Assert that handle
is valid for this arena.
Trait Implementations§
source§impl<T> Clone for UniqueArena<T>where
T: Clone,
impl<T> Clone for UniqueArena<T>where
T: Clone,
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> Debug for UniqueArena<T>
impl<T> Debug for UniqueArena<T>
source§impl<T> Default for UniqueArena<T>
impl<T> Default for UniqueArena<T>
source§fn default() -> UniqueArena<T>
fn default() -> UniqueArena<T>
source§impl<'de, T> Deserialize<'de> for UniqueArena<T>
Available on crate feature deserialize
only.
impl<'de, T> Deserialize<'de> for UniqueArena<T>
deserialize
only.source§fn deserialize<D>(
deserializer: D
) -> Result<UniqueArena<T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D
) -> Result<UniqueArena<T>, <D as Deserializer<'de>>::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>
Available on crate feature serialize
only.
impl<T> Serialize for UniqueArena<T>
serialize
only.