[][src]Struct tokenlock::TokenLock

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

A mutual exclusive primitive that can be accessed using a Token<I> with a very low over-head.

See the module-level documentation for more details.

Implementations

impl<T, I> TokenLock<T, I>[src]

pub const fn new(keyhole: I, data: T) -> Self[src]

Construct a TokenLock.

pub fn into_inner(self) -> T[src]

Consume this TokenLock, returning the contained data.

impl<T: ?Sized, I> TokenLock<T, I>[src]

pub const fn keyhole(&self) -> &I[src]

Get a reference to the contained I (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<I>>(&'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<I>>(&'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<I>>(
    &'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<I>>(
    &'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, I> TokenLock<T, I>[src]

pub fn get<K: Token<I>>(&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<I>>(&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<I>>(&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<I>>(&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<I>>(&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<I>>(
    &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<I>>(
    &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<I> + 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<I> + 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, I: Clone> TokenLock<T, I>[src]

pub fn clone<K: Token<I>>(&self, token: &K) -> Self[src]

Clone the TokenLock. Panic if token doesn't fit in the keyhole.

pub fn try_clone<K: Token<I>>(&self, token: &K) -> Result<Self, BadTokenError>[src]

Clone the TokenLock. Return BadTokenError if token doesn't fit in the keyhole.

Trait Implementations

impl<T: ?Sized, I: Debug> Debug for TokenLock<T, I>[src]

impl<T: Default + ?Sized, I: Default> Default for TokenLock<T, I>[src]

impl<T: ?Sized + Send + Sync, I: Send> Send for TokenLock<T, I>[src]

impl<T: ?Sized + Send + Sync, I: Sync> Sync for TokenLock<T, I>[src]

Auto Trait Implementations

impl<T, I> !RefUnwindSafe for TokenLock<T, I>

impl<T: ?Sized, I> Unpin for TokenLock<T, I> where
    I: Unpin,
    T: Unpin

impl<T: ?Sized, I> UnwindSafe for TokenLock<T, I> where
    I: UnwindSafe,
    T: UnwindSafe

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.