Struct tokenlock::UnsyncTokenLock
source · [−]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
sourceimpl<T, Keyhole> UnsyncTokenLock<T, Keyhole>
impl<T, Keyhole> UnsyncTokenLock<T, Keyhole>
sourceimpl<T: ?Sized, Keyhole> UnsyncTokenLock<T, Keyhole>
impl<T: ?Sized, Keyhole> UnsyncTokenLock<T, Keyhole>
sourceimpl<T: ?Sized, Keyhole> UnsyncTokenLock<T, Keyhole>
impl<T: ?Sized, Keyhole> UnsyncTokenLock<T, Keyhole>
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
.
sourceimpl<T, Keyhole> UnsyncTokenLock<T, Keyhole>
impl<T, Keyhole> UnsyncTokenLock<T, Keyhole>
sourcepub fn get<K: Token<Keyhole> + Unsync>(&self, token: &K) -> T where
T: Clone,
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
.
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) -> T where
T: Default,
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
.
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.
sourceimpl<T: Clone, Keyhole: Clone> UnsyncTokenLock<T, Keyhole>
impl<T: Clone, Keyhole: Clone> UnsyncTokenLock<T, Keyhole>
Trait Implementations
sourceimpl<T: ConstDefault, Keyhole: ConstDefault> ConstDefault for UnsyncTokenLock<T, Keyhole>
impl<T: ConstDefault, Keyhole: ConstDefault> ConstDefault for UnsyncTokenLock<T, Keyhole>
sourceimpl<T: ?Sized, Keyhole: Debug> Debug for UnsyncTokenLock<T, Keyhole>
impl<T: ?Sized, Keyhole: Debug> Debug for UnsyncTokenLock<T, Keyhole>
sourceimpl<T: Default + ?Sized, Keyhole: Default> Default for UnsyncTokenLock<T, Keyhole>
impl<T: Default + ?Sized, Keyhole: Default> Default for UnsyncTokenLock<T, Keyhole>
sourcefn default() -> UnsyncTokenLock<T, Keyhole>
fn default() -> UnsyncTokenLock<T, Keyhole>
Returns the “default value” for a type. Read more
impl<T: ?Sized + Send, Keyhole: Send> Send for UnsyncTokenLock<T, Keyhole>
impl<T: ?Sized + Send, Keyhole: Sync> Sync for UnsyncTokenLock<T, Keyhole>
Auto Trait Implementations
impl<T, Keyhole> !RefUnwindSafe for UnsyncTokenLock<T, Keyhole>
impl<T: ?Sized, Keyhole> Unpin for UnsyncTokenLock<T, Keyhole> where
Keyhole: Unpin,
T: Unpin,
impl<T: ?Sized, Keyhole> UnwindSafe for UnsyncTokenLock<T, Keyhole> where
Keyhole: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more