Struct IdentityValues

Source
pub(crate) struct IdentityValues {
    free: Vec<(u32, u32)>,
    next_index: u32,
    count: usize,
    id_source: IdSource,
}
Expand description

A simple structure to allocate Id identifiers.

Calling alloc returns a fresh, never-before-seen id. Calling release marks an id as dead; it will never be returned again by alloc.

IdentityValues returns Ids whose index values are suitable for use as indices into a Vec<T> that holds those ids’ referents:

  • Every live id has a distinct index value. Every live id’s index selects a distinct element in the vector.

  • IdentityValues prefers low index numbers. If you size your vector to accommodate the indices produced here, the vector’s length will reflect the highwater mark of actual occupancy.

  • IdentityValues reuses the index values of freed ids before returning ids with new index values. Freed vector entries get reused.

  • The non-reuse property is achieved by storing an epoch alongside the index in an Id. Index values are reused, but only with a different epoch.

IdentityValues can also be used to track the count of IDs allocated by some external allocator. Combining internal and external allocation is not allowed; calling both alloc and mark_as_used on the same IdentityValues will result in a panic. The external mode is used when playing back a trace of wgpu operations.

Fields§

§free: Vec<(u32, u32)>§next_index: u32§count: usize§id_source: IdSource

Implementations§

Source§

impl IdentityValues

Source

pub fn alloc<T: Marker>(&mut self) -> Id<T>

Allocate a fresh, never-before-seen ID.

§Panics

If mark_as_used has previously been called on this IdentityValues.

Source

pub fn mark_as_used<T: Marker>(&mut self, id: Id<T>) -> Id<T>

Increment the count of used IDs.

§Panics

If alloc has previously been called on this IdentityValues.

Source

pub fn release<T: Marker>(&mut self, id: Id<T>)

Free id and/or decrement the count of used IDs.

Freed IDs will never be returned from alloc again.

Source

pub fn count(&self) -> usize

Trait Implementations§

Source§

impl Debug for IdentityValues

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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

impl<T> Upcast<T> for T

§

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

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

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