naga

Struct 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§

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§

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: 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

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.