Struct wgpu_core::track::metadata::ResourceMetadata

source ·
pub(super) struct ResourceMetadata<T: Clone> {
    owned: BitVec<usize>,
    resources: Vec<Option<T>>,
}
Expand description

A set of resources, holding a Arc<T> and epoch for each member.

Testing for membership is fast, and iterating over members is reasonably fast in practice. Storage consumption is proportional to the largest id index of any member, not to the number of members, but a bit vector tracks occupancy, so iteration touches only occupied elements.

Fields§

§owned: BitVec<usize>

If the resource with index i is a member, owned[i] is true.

§resources: Vec<Option<T>>

A vector holding clones of members’ Ts.

Implementations§

source§

impl<T: Clone> ResourceMetadata<T>

source

pub(super) fn new() -> Self

source

pub(super) fn set_size(&mut self, size: usize)

source

pub(super) fn clear(&mut self)

source

pub(super) fn tracker_assert_in_bounds(&self, index: usize)

Ensures a given index is in bounds for all arrays and does sanity checks of the presence of a refcount.

In release mode this function is completely empty and is removed.

source

pub(super) fn is_empty(&self) -> bool

Returns true if the tracker owns no resources.

This is a O(n) operation.

source

pub(super) fn contains(&self, index: usize) -> bool

Returns true if the set contains the resource with the given index.

source

pub(super) unsafe fn contains_unchecked(&self, index: usize) -> bool

Returns true if the set contains the resource with the given index.

§Safety

The given index must be in bounds for this ResourceMetadata’s existing tables. See tracker_assert_in_bounds.

source

pub(super) unsafe fn insert(&mut self, index: usize, resource: T) -> &T

Insert a resource into the set.

Add the resource with the given index, epoch, and reference count to the set.

Returns a reference to the newly inserted resource. (This allows avoiding a clone/reference count increase in many cases.)

§Safety

The given index must be in bounds for this ResourceMetadata’s existing tables. See tracker_assert_in_bounds.

source

pub(super) unsafe fn get_resource_unchecked(&self, index: usize) -> &T

Get the resource with the given index.

§Safety

The given index must be in bounds for this ResourceMetadata’s existing tables. See tracker_assert_in_bounds.

source

pub(super) fn owned_resources(&self) -> impl Iterator<Item = &T> + '_

Returns an iterator over the resources owned by self.

source

pub(super) fn owned_indices(&self) -> impl Iterator<Item = usize> + '_

Returns an iterator over the indices of all resources owned by self.

source

pub(super) unsafe fn remove(&mut self, index: usize)

Remove the resource with the given index from the set.

Trait Implementations§

source§

impl<T: Debug + Clone> Debug for ResourceMetadata<T>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for ResourceMetadata<T>

§

impl<T> RefUnwindSafe for ResourceMetadata<T>
where T: RefUnwindSafe,

§

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

§

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

§

impl<T> Unpin for ResourceMetadata<T>
where T: Unpin,

§

impl<T> UnwindSafe for ResourceMetadata<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> Downcast<T> for T

source§

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

impl<T> Upcast<T> for T

source§

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,