Struct naga::UniqueArena
source · [−]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 may not be mutated.
UniqueArena
is similar to Arena
: If Arena
is vector-like,
UniqueArena
is HashSet
-like.
Implementations
sourceimpl<T> UniqueArena<T>
impl<T> UniqueArena<T>
sourcepub fn get_span(&self, handle: Handle<T>) -> Span
pub fn get_span(&self, handle: Handle<T>) -> Span
Return the span associated with handle
.
If a value has been inserted multiple times, the span returned is the one provided with the first insertion.
If the span
feature is not enabled, always return Span::default
.
This can be detected with Span::is_defined
.
sourceimpl<T: Eq + Hash> UniqueArena<T>
impl<T: Eq + Hash> UniqueArena<T>
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 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
.
When the span
feature is enabled, 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 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.
Trait Implementations
sourceimpl<'a, T> Arbitrary<'a> for UniqueArena<T> where
T: Eq + Hash + Arbitrary<'a>,
impl<'a, T> Arbitrary<'a> for UniqueArena<T> where
T: Eq + Hash + Arbitrary<'a>,
sourcefn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Generate an arbitrary value of Self
from the given unstructured data. Read more
sourcefn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self>
Generate an arbitrary value of Self
from the entirety of the given
unstructured data. Read more
sourceimpl<T> Default for UniqueArena<T>
impl<T> Default for UniqueArena<T>
sourceimpl<'de, T> Deserialize<'de> for UniqueArena<T> where
T: Eq + Hash + Deserialize<'de>,
impl<'de, T> Deserialize<'de> for UniqueArena<T> where
T: Eq + Hash + Deserialize<'de>,
sourcefn 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>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl<T> Index<Handle<T>> for UniqueArena<T>
impl<T> Index<Handle<T>> for UniqueArena<T>
Auto Trait Implementations
impl<T> RefUnwindSafe for UniqueArena<T> where
T: RefUnwindSafe,
impl<T> Send for UniqueArena<T> where
T: Send,
impl<T> Sync for UniqueArena<T> where
T: Sync,
impl<T> Unpin for UniqueArena<T> where
T: Unpin,
impl<T> UnwindSafe for UniqueArena<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more