Struct wgpu_core::snatch::Snatchable

source ·
pub struct Snatchable<T> {
    value: UnsafeCell<Option<T>>,
}
Expand description

A value that is mostly immutable but can be “snatched” if we need to destroy it early.

In order to safely access the underlying data, the device’s global snatchable lock must be taken. To guarantee it, methods take a read or write guard of that special lock.

Fields§

§value: UnsafeCell<Option<T>>

Implementations§

source§

impl<T> Snatchable<T>

source

pub fn new(val: T) -> Self

source

pub fn get<'a>(&'a self, _guard: &'a SnatchGuard<'_>) -> Option<&'a T>

Get read access to the value. Requires a the snatchable lock’s read guard.

source

pub fn snatch(&self, _guard: &mut ExclusiveSnatchGuard<'_>) -> Option<T>

Take the value. Requires a the snatchable lock’s write guard.

source

pub fn take(&mut self) -> Option<T>

Take the value without a guard. This can only be used with exclusive access to self, so it does not require locking.

Typically useful in a drop implementation.

Trait Implementations§

source§

impl<T> Debug for Snatchable<T>

source§

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

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

impl<T> Sync for Snatchable<T>

Auto Trait Implementations§

§

impl<T> !Freeze for Snatchable<T>

§

impl<T> !RefUnwindSafe for Snatchable<T>

§

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

§

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

§

impl<T> UnwindSafe for Snatchable<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>,

§

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