Struct naga::UniqueArena

source ·
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 may not be mutated.

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>

source

pub fn new() -> Self

Create a new arena with no initial capacity allocated.

source

pub fn len(&self) -> usize

Return the current number of items stored in this arena.

source

pub fn is_empty(&self) -> bool

Return true if the arena contains no elements.

source

pub fn clear(&mut self)

Clears the arena, keeping all allocations.

source

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.

source

pub(crate) fn drain_all(&mut self) -> UniqueArenaDrain<'_, T>

source§

impl<T: Eq + Hash> UniqueArena<T>

source

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.

source

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.

source

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
source

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.

source

pub fn get_handle(&self, handle: Handle<T>) -> Result<&T, BadHandle>

Return this arena’s value at handle, if that is a valid handle.

source

pub fn check_contains_handle(&self, handle: Handle<T>) -> Result<(), BadHandle>

Assert that handle is valid for this arena.

Trait Implementations§

source§

impl<T: Hash + Eq> ArenaType<T> for UniqueArena<T>

source§

fn len(&self) -> usize

source§

impl<T: Clone> Clone for UniqueArena<T>

source§

fn clone(&self) -> UniqueArena<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug + Eq + Hash> Debug for UniqueArena<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> Default for UniqueArena<T>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<T> Index<Handle<T>> for UniqueArena<T>

source§

type Output = T

The returned type after indexing.
source§

fn index(&self, handle: Handle<T>) -> &T

Performs the indexing (container[index]) operation. Read more
source§

impl<T> SpanProvider<T> for UniqueArena<T>

source§

fn get_span(&self, handle: Handle<T>) -> Span

source§

fn get_span_context(&self, handle: Handle<T>) -> SpanContext

Auto Trait Implementations§

§

impl<T> Freeze for UniqueArena<T>

§

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§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.