Struct tokenlock::TokenLock[][src]

pub struct TokenLock<T: ?Sized, Keyhole> { /* fields omitted */ }

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]

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]

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]

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]

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]

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]

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]

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]

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]

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.

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

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

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]

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]

impl<T: ?Sized, Keyhole> UnwindSafe for TokenLock<T, Keyhole> where
    Keyhole: UnwindSafe,
    T: UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.