pub struct UnsyncTokenLock<T: ?Sized, Keyhole> { /* private fields */ }
Expand description
Like TokenLock
, but the usable Token
s 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
impl<T, Keyhole> UnsyncTokenLock<T, Keyhole>
§Construction and Destruction
Source§impl<T: ?Sized, Keyhole> UnsyncTokenLock<T, Keyhole>
§Miscellaneous
impl<T: ?Sized, Keyhole> UnsyncTokenLock<T, Keyhole>
§Miscellaneous
Source§impl<T: ?Sized, Keyhole> UnsyncTokenLock<T, Keyhole>
§Borrowing
impl<T: ?Sized, Keyhole> UnsyncTokenLock<T, Keyhole>
§Borrowing
Sourcepub fn read<'a, K: Token<Keyhole> + Unsync>(&'a self, token: &'a K) -> &'a T
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
.
Sourcepub fn write<'a, K: Token<Keyhole>>(&'a self, token: &'a mut K) -> &'a mut T
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
.
Sourcepub fn try_read<'a, K: Token<Keyhole> + Unsync>(
&'a self,
token: &'a K,
) -> Result<&'a T, BadTokenError>
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§impl<T, Keyhole> UnsyncTokenLock<T, Keyhole>
§Utilities
impl<T, Keyhole> UnsyncTokenLock<T, Keyhole>
§Utilities
Sourcepub fn get<K: Token<Keyhole> + Unsync>(&self, token: &K) -> Twhere
T: Clone,
pub fn get<K: Token<Keyhole> + Unsync>(&self, token: &K) -> Twhere
T: Clone,
Get the contained data by cloning. Panic if token
doesn’t fit in
the keyhole
.
Sourcepub fn try_get<K: Token<Keyhole> + Unsync>(
&self,
token: &K,
) -> Result<T, BadTokenError>where
T: Clone,
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
.
Sourcepub fn set<K: Token<Keyhole>>(&self, token: &mut K, value: T)
pub fn set<K: Token<Keyhole>>(&self, token: &mut K, value: T)
Assign a new value. Panic if token
doesn’t fit in thekeyhole
.
Sourcepub fn try_set<K: Token<Keyhole>>(
&self,
token: &mut K,
value: T,
) -> Result<(), BadTokenError>
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
.
Sourcepub fn take<K: Token<Keyhole>>(&self, token: &mut K) -> Twhere
T: Default,
pub fn take<K: Token<Keyhole>>(&self, token: &mut K) -> Twhere
T: Default,
Take the contained data, leaving Default::default()
in its place.
Panic if token
doesn’t fit in the keyhole
.
Sourcepub fn try_take<K: Token<Keyhole>>(
&self,
token: &mut K,
) -> Result<T, BadTokenError>where
T: Default,
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
.
Sourcepub fn replace<K: Token<Keyhole>>(&self, token: &mut K, t: T) -> T
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
.
Sourcepub fn replace_with<K: Token<Keyhole>>(
&self,
token: &mut K,
f: impl FnOnce(&mut T) -> T,
) -> T
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
.
Sourcepub fn try_replace_with<K: Token<Keyhole>>(
&self,
token: &mut K,
f: impl FnOnce(&mut T) -> T,
) -> Result<T, BadTokenError>
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
.
Sourcepub fn swap<IOther, K: Token<Keyhole> + Token<IOther>>(
&self,
token: &mut K,
other: &UnsyncTokenLock<T, IOther>,
)
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
TokenLock
s.
This function corresponds to std::mem::swap
.
Sourcepub fn try_swap<IOther, K: Token<Keyhole> + Token<IOther>>(
&self,
token: &mut K,
other: &UnsyncTokenLock<T, IOther>,
) -> Result<(), BadTokenError>
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 TokenLock
s.