Struct wgpu_core::hub::Token

source ·
pub(crate) struct Token<'a, T: 'a> {
    level: PhantomData<&'a *const T>,
}
Expand description

A zero-size permission token to lock some fields of Hub.

Access to a Token<T> grants permission to lock any field of Hub following the one of type [Registry<T, ...>], where “following” is as defined by the Access implementations.

Calling Token::root() returns a Token<Root>, which grants permission to lock any field. Dynamic checks ensure that each thread has at most one Token<Root> live at a time, in debug builds.

The locking methods on Registry<T, ...> take a &'t mut Token<A>, and return a fresh Token<'t, T> and a lock guard with lifetime 't, so the caller cannot access their Token<A> again until they have dropped both the Token<T> and the lock guard.

Tokens are !Send, so one thread can’t send its permissions to another.

Fields§

§level: PhantomData<&'a *const T>

Implementations§

source§

impl<'a, T> Token<'a, T>

source

pub(crate) fn new() -> Self

Return a new token for a locked field.

This should only be used by Registry locking methods.

source§

impl Token<'static, Root>

source

pub fn root() -> Self

Return a Token<Root>, granting permission to lock any Hub field.

Debug builds check dynamically that each thread has at most one root token at a time.

Trait Implementations§

source§

impl<'a, T> Drop for Token<'a, T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a, T> RefUnwindSafe for Token<'a, T>where T: RefUnwindSafe,

§

impl<'a, T> !Send for Token<'a, T>

§

impl<'a, T> !Sync for Token<'a, T>

§

impl<'a, T> Unpin for Token<'a, T>

§

impl<'a, T> UnwindSafe for Token<'a, T>where T: RefUnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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 Twhere 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 Twhere 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.