Struct UnsyncTokenLock

Source
pub struct UnsyncTokenLock<T: ?Sized, Keyhole> { /* private fields */ }
Expand description

Like TokenLock, but the usable Tokens are constrained by Unsync. This subtle difference allows it to be Sync even if T is not.

See the module-level documentation for more details.

Implementations§

Source§

impl<T, Keyhole> UnsyncTokenLock<T, Keyhole>

§Construction and Destruction

Source

pub const fn new(keyhole: Keyhole, data: T) -> Self

Construct a Self.

Source

pub fn wrap(data: T) -> Self
where Keyhole: Default,

Construct a Self with a default-constructed Keyhole.

Source

pub fn into_inner(self) -> T

Consume self, returning the contained data.

Source§

impl<T: ?Sized, Keyhole> UnsyncTokenLock<T, Keyhole>

§Miscellaneous

Source

pub const fn keyhole(&self) -> &Keyhole

Get a reference to the contained Keyhole (keyhole).

Source

pub const fn as_ptr(&self) -> *mut T

Get a raw pointer to the contained data.

Source§

impl<T: ?Sized, Keyhole> UnsyncTokenLock<T, Keyhole>

§Borrowing

Source

pub fn read<'a, K: Token<Keyhole> + Unsync>(&'a self, token: &'a K) -> &'a T

Get a reference to the contained data. Panic if token doesn’t fit in the keyhole.

Source

pub fn write<'a, K: Token<Keyhole>>(&'a self, token: &'a mut K) -> &'a mut T

Get a mutable reference to the contained data. Panic if token doesn’t fit in the keyhole.

Source

pub fn try_read<'a, K: Token<Keyhole> + Unsync>( &'a self, token: &'a K, ) -> Result<&'a T, BadTokenError>

Get a reference to the contained data. Return BadTokenError if token doesn’t fit in the keyhole.

Source

pub fn try_write<'a, K: Token<Keyhole>>( &'a self, token: &'a mut K, ) -> Result<&'a mut T, BadTokenError>

Get a mutable reference to the contained data. Return BadTokenError if token doesn’t fit in the keyhole.

Source

pub fn get_mut(&mut self) -> &mut T

Get a mutable reference to the contained data.

Source§

impl<T, Keyhole> UnsyncTokenLock<T, Keyhole>

§Utilities

Source

pub fn get<K: Token<Keyhole> + Unsync>(&self, token: &K) -> T
where T: Clone,

Get the contained data by cloning. Panic if token doesn’t fit in the keyhole.

Source

pub fn try_get<K: Token<Keyhole> + Unsync>( &self, token: &K, ) -> Result<T, BadTokenError>
where T: Clone,

Get the contained data by cloning. Return BadTokenError if token doesn’t fit in the keyhole.

Source

pub fn set<K: Token<Keyhole>>(&self, token: &mut K, value: T)

Assign a new value. Panic if token doesn’t fit in thekeyhole.

Source

pub fn try_set<K: Token<Keyhole>>( &self, token: &mut K, value: T, ) -> Result<(), BadTokenError>

Assign a new value. Return BadTokenError if token doesn’t fit in the keyhole.

Source

pub fn take<K: Token<Keyhole>>(&self, token: &mut K) -> T
where T: Default,

Take the contained data, leaving Default::default() in its place. Panic if token doesn’t fit in the keyhole.

Source

pub fn try_take<K: Token<Keyhole>>( &self, token: &mut K, ) -> Result<T, BadTokenError>
where T: Default,

Take the contained data, leaving Default::default() in its place. Return BadTokenError if token doesn’t fit in the keyhole.

Source

pub fn replace<K: Token<Keyhole>>(&self, token: &mut K, t: T) -> T

Replace the contained data with a new one. Panic if token doesn’t fit in the keyhole.

This function corresponds to std::mem::replace.

Source

pub fn replace_with<K: Token<Keyhole>>( &self, token: &mut K, f: impl FnOnce(&mut T) -> T, ) -> T

Replace the contained data with a new one computed by the given closure. Panic if token doesn’t fit in the keyhole.

This function corresponds to std::mem::replace.

Source

pub fn try_replace_with<K: Token<Keyhole>>( &self, token: &mut K, f: impl FnOnce(&mut T) -> T, ) -> Result<T, BadTokenError>

Replace the contained data with a new one computed by f. Panic if token doesn’t fit in the keyhole.

This function corresponds to std::mem::replace.

Source

pub fn swap<IOther, K: Token<Keyhole> + Token<IOther>>( &self, token: &mut K, other: &UnsyncTokenLock<T, IOther>, )

Swap the contained data with the contained data of other. Panic if token doesn’t fit in the keyhole of both TokenLocks.

This function corresponds to std::mem::swap.

Source

pub fn try_swap<IOther, K: Token<Keyhole> + Token<IOther>>( &self, token: &mut K, other: &UnsyncTokenLock<T, IOther>, ) -> Result<(), BadTokenError>

Swap the contained data with the contained data of other. Return BadTokenError if token doesn’t fit in the keyhole of both TokenLocks.

Source§

impl<T: Clone, Keyhole: Clone> UnsyncTokenLock<T, Keyhole>

§Cloning

Source

pub fn clone<K: Token<Keyhole> + Unsync>(&self, token: &K) -> Self

Clone self. Panic if token doesn’t fit in the keyhole.

Source

pub fn try_clone<K: Token<Keyhole> + Unsync>( &self, token: &K, ) -> Result<Self, BadTokenError>

Clone self. Return BadTokenError if token doesn’t fit in the keyhole.

Trait Implementations§

Source§

impl<T: ConstDefault, Keyhole: ConstDefault> ConstDefault for UnsyncTokenLock<T, Keyhole>

Source§

const DEFAULT: Self

The constant default value.
Source§

impl<T: ?Sized, Keyhole: Debug> Debug for UnsyncTokenLock<T, Keyhole>

Source§

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

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

impl<T: Default + ?Sized, Keyhole: Default> Default for UnsyncTokenLock<T, Keyhole>

Source§

fn default() -> UnsyncTokenLock<T, Keyhole>

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

impl<T: ?Sized + Send, Keyhole: Send> Send for UnsyncTokenLock<T, Keyhole>

Source§

impl<T: ?Sized + Send, Keyhole: Sync> Sync for UnsyncTokenLock<T, Keyhole>

Auto Trait Implementations§

§

impl<T, Keyhole> !Freeze for UnsyncTokenLock<T, Keyhole>

§

impl<T, Keyhole> !RefUnwindSafe for UnsyncTokenLock<T, Keyhole>

§

impl<T, Keyhole> Unpin for UnsyncTokenLock<T, Keyhole>
where Keyhole: Unpin, T: Unpin + ?Sized,

§

impl<T, Keyhole> UnwindSafe for UnsyncTokenLock<T, Keyhole>
where Keyhole: UnwindSafe, T: UnwindSafe + ?Sized,

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