Struct tokenlock::TokenLock [−][src]
A mutual exclusive primitive that can be accessed using a Token
<Keyhole>
with a very low overhead.
See the module-level documentation for more details.
Implementations
impl<T, Keyhole> TokenLock<T, Keyhole>
[src]
pub const fn new(keyhole: Keyhole, data: T) -> Self
[src]
Construct a Self
.
pub fn into_inner(self) -> T
[src]
Consume self
, returning the contained data.
impl<T: ?Sized, Keyhole> TokenLock<T, Keyhole>
[src]
pub const fn keyhole(&self) -> &Keyhole
[src]
Get a reference to the contained Keyhole
(keyhole).
pub fn get_mut(&mut self) -> &mut T
[src]
Get a mutable reference to the contained data.
pub const fn as_ptr(&self) -> *mut T
[src]
Get a raw pointer to the contained data.
pub fn read<'a, K: Token<Keyhole>>(&'a self, token: &'a K) -> &'a T
[src]
Get a reference to the contained data. Panic if token
doesn't fit in
the keyhole
.
pub fn write<'a, K: Token<Keyhole>>(&'a self, token: &'a mut K) -> &'a mut T
[src]
Get a mutable reference to the contained data. Panic if token
doesn't
fit in the keyhole
.
pub fn try_read<'a, K: Token<Keyhole>>(
&'a self,
token: &'a K
) -> Result<&'a T, BadTokenError>
[src]
&'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
.
pub fn try_write<'a, K: Token<Keyhole>>(
&'a self,
token: &'a mut K
) -> Result<&'a mut T, BadTokenError>
[src]
&'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
.
impl<T, Keyhole> TokenLock<T, Keyhole>
[src]
pub fn get<K: Token<Keyhole>>(&self, token: &K) -> T where
T: Clone,
[src]
T: Clone,
Get the contained data by cloning. Panic if token
doesn't fit in
the keyhole
.
pub fn try_get<K: Token<Keyhole>>(&self, token: &K) -> Result<T, BadTokenError> where
T: Clone,
[src]
T: Clone,
Get the contained data by cloning. Return BadTokenError
if token
doesn't fit in the keyhole
.
pub fn take<K: Token<Keyhole>>(&self, token: &mut K) -> T where
T: Default,
[src]
T: Default,
Take the contained data, leaving Default::default()
in its place.
Panic if token
doesn't fit in the keyhole
.
pub fn try_take<K: Token<Keyhole>>(
&self,
token: &mut K
) -> Result<T, BadTokenError> where
T: Default,
[src]
&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
.
pub fn replace<K: Token<Keyhole>>(&self, token: &mut K, t: T) -> T
[src]
Replace the contained data with a new one. Panic if token
doesn't fit
in the keyhole
.
This function corresponds to std::mem::replace
.
pub fn replace_with<K: Token<Keyhole>>(
&self,
token: &mut K,
f: impl FnOnce(&mut T) -> T
) -> T
[src]
&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
.
pub fn try_replace_with<K: Token<Keyhole>>(
&self,
token: &mut K,
f: impl FnOnce(&mut T) -> T
) -> Result<T, BadTokenError>
[src]
&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
.
pub fn swap<IOther, K: Token<Keyhole> + Token<IOther>>(
&self,
token: &mut K,
other: &TokenLock<T, IOther>
)
[src]
&self,
token: &mut K,
other: &TokenLock<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
.
pub fn try_swap<IOther, K: Token<Keyhole> + Token<IOther>>(
&self,
token: &mut K,
other: &TokenLock<T, IOther>
) -> Result<(), BadTokenError>
[src]
&self,
token: &mut K,
other: &TokenLock<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.
impl<T: Clone, Keyhole: Clone> TokenLock<T, Keyhole>
[src]
pub fn clone<K: Token<Keyhole>>(&self, token: &K) -> Self
[src]
Clone self
. Panic if token
doesn't fit in the
keyhole
.
pub fn try_clone<K: Token<Keyhole>>(
&self,
token: &K
) -> Result<Self, BadTokenError>
[src]
&self,
token: &K
) -> Result<Self, BadTokenError>
Clone self
. Return BadTokenError
if token
doesn't fit in
the keyhole
.
Trait Implementations
impl<T: ?Sized, Keyhole: Debug> Debug for TokenLock<T, Keyhole>
[src]
impl<T: Default + ?Sized, Keyhole: Default> Default for TokenLock<T, Keyhole>
[src]
impl<T: ?Sized + Send, Keyhole: Send> Send for TokenLock<T, Keyhole>
[src]
impl<T: ?Sized + Send + Sync, Keyhole: Sync> Sync for TokenLock<T, Keyhole>
[src]
Auto Trait Implementations
impl<T, Keyhole> !RefUnwindSafe for TokenLock<T, Keyhole>
[src]
impl<T: ?Sized, Keyhole> Unpin for TokenLock<T, Keyhole> where
Keyhole: Unpin,
T: Unpin,
[src]
Keyhole: Unpin,
T: Unpin,
impl<T: ?Sized, Keyhole> UnwindSafe for TokenLock<T, Keyhole> where
Keyhole: UnwindSafe,
T: UnwindSafe,
[src]
Keyhole: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,