Struct wgpu::naga::UniqueArena

source ·
pub struct UniqueArena<T> { /* private fields */ }
Available on 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>

source

pub fn new() -> UniqueArena<T>

Available on wgpu_core only.

Create a new arena with no initial capacity allocated.

source

pub fn len(&self) -> usize

Available on wgpu_core only.

Return the current number of items stored in this arena.

source

pub fn is_empty(&self) -> bool

Available on wgpu_core only.

Return true if the arena contains no elements.

source

pub fn clear(&mut self)

Available on wgpu_core only.

Clears the arena, keeping all allocations.

source

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

Available on wgpu_core only.

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> UniqueArena<T>
where T: Eq + Hash,

source

pub fn iter(&self) -> impl DoubleEndedIterator

Available on wgpu_core only.

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>

Available on 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.

source

pub fn replace(&mut self, old: Handle<T>, new: T)

Available on 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
source

pub fn get(&self, value: &T) -> Option<Handle<T>>

Available on 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.

source

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

Available on wgpu_core only.

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>

Available on wgpu_core only.

Assert that handle is valid for this arena.

Trait Implementations§

source§

impl<'a, T> Arbitrary<'a> for UniqueArena<T>
where T: Eq + Hash + Arbitrary<'a>,

Available on crate feature arbitrary only.
source§

fn arbitrary(u: &mut Unstructured<'a>) -> Result<UniqueArena<T>, Error>

Generate an arbitrary value of Self from the given unstructured data. Read more
source§

fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<UniqueArena<T>, Error>

Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more
source§

fn size_hint(depth: usize) -> (usize, Option<usize>)

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
source§

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

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 for UniqueArena<T>
where T: Debug + Eq + Hash,

source§

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

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

impl<T> Default for UniqueArena<T>

source§

fn default() -> UniqueArena<T>

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

impl<'de, T> Deserialize<'de> for UniqueArena<T>
where T: Eq + Hash + Deserialize<'de>,

Available on crate feature deserialize only.
source§

fn deserialize<D>( deserializer: D ) -> Result<UniqueArena<T>, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

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

§

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> Serialize for UniqueArena<T>
where T: Eq + Hash + Serialize,

Available on crate feature serialize only.
source§

fn serialize<S>( &self, serializer: S ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

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§

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
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

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,

§

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

§

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

§

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

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

impl<T> WasmNotSend for T
where T: Send,

source§

impl<T> WasmNotSendSync for T

source§

impl<T> WasmNotSync for T
where T: Sync,