Struct tokenlock::SingletonTokenRefMut[][src]

pub struct SingletonTokenRefMut<'a, Tag: ?Sized, Variant = SyncVariant>(_);

Zero-sized logical equivalent of &'a mut SingletonToken<Tag>.

The second type parameter (Variant) is internal use only and exempt from the API stability guarantee.

Examples

struct MyTag;
impl_singleton_token_factory!(MyTag);
let mut token = SingletonToken::<MyTag>::new().unwrap();
let lock = TokenLock::new(token.id(), 1);

// `SingletonTokenRefMut` is zero-sized (unlike `&SingletonToken`), so there is
// no runtime overhead involved with passing `SingletonTokenRefMut`.
access_lock(token.borrow_mut(), &lock);

fn access_lock(
    mut token: SingletonTokenRefMut<'_, MyTag>,
    lock: &TokenLock<u32, SingletonTokenId<MyTag>>,
) {
    assert_eq!(*lock.read(&*token), 1);
    lock.replace(&mut *token, 2);
}

SingletonTokenRefMut is Send-able because SingletonToken is Send:

let token: &'static mut SingletonTokenGuard<MyTag> =
    Box::leak(Box::new(SingletonToken::<MyTag>::new().unwrap()));
let token_ref: SingletonTokenRefMut<MyTag> = token.borrow_mut();
std::thread::spawn(move || {
    let _token_ref = token_ref;
});

Methods from Deref<Target = SingletonToken<Tag, Variant>>

pub fn id(&self) -> SingletonTokenId<Tag>[src]

Construct an SingletonTokenId that equates to self.

pub fn borrow(&self) -> SingletonTokenRef<'_, Tag, Variant>[src]

Borrow self as SingletonTokenRef or UnsyncSingletonTokenRef of the same Sync-ness as Self.

SingletonTokenRef is truly zero-sized, so it's more efficient to store and pass than &SingletonToken.

pub fn borrow_mut(&mut self) -> SingletonTokenRefMut<'_, Tag, Variant>[src]

Borrow self mutably as SingletonTokenRefMut or UnsyncSingletonTokenRefMut of the same Sync-ness as Self.

SingletonTokenRefMut is truly zero-sized, so it's more efficient to store and pass than &mut SingletonToken.

pub fn borrow_sync(&self) -> SingletonTokenRef<'_, Tag>[src]

Borrow self: UnsyncSingletonToken as SingletonTokenRef.

pub fn borrow_sync_mut(&mut self) -> SingletonTokenRefMut<'_, Tag>[src]

Borrow self: UnsyncSingletonToken mutably as SingletonTokenRefMut.

pub fn borrow_unsync_mut(&mut self) -> UnsyncSingletonTokenRefMut<'_, Tag>[src]

Borrow self: SingletonToken mutably as UnsyncSingletonTokenRefMut.

There is no borrow_unsync because that would allow UnsyncSingletonToken to be logically borrowed by multiple threads.

Trait Implementations

impl<Tag: ?Sized, Variant: SingletonTokenVariant> Debug for SingletonTokenRefMut<'_, Tag, Variant>[src]

impl<Tag: ?Sized, Variant: SingletonTokenVariant> Deref for SingletonTokenRefMut<'_, Tag, Variant>[src]

type Target = SingletonToken<Tag, Variant>

The resulting type after dereferencing.

impl<Tag: ?Sized, Variant: SingletonTokenVariant> DerefMut for SingletonTokenRefMut<'_, Tag, Variant>[src]

impl<Tag: ?Sized, Variant: SingletonTokenVariant> Eq for SingletonTokenRefMut<'_, Tag, Variant>[src]

impl<Tag: ?Sized, Variant: SingletonTokenVariant> Hash for SingletonTokenRefMut<'_, Tag, Variant>[src]

impl<Tag: ?Sized, Variant: SingletonTokenVariant> PartialEq<SingletonTokenRefMut<'_, Tag, Variant>> for SingletonTokenRefMut<'_, Tag, Variant>[src]

Auto Trait Implementations

impl<'a, Tag: ?Sized, Variant> RefUnwindSafe for SingletonTokenRefMut<'a, Tag, Variant> where
    Variant: RefUnwindSafe
[src]

impl<'a, Tag: ?Sized, Variant> Send for SingletonTokenRefMut<'a, Tag, Variant> where
    Variant: Send
[src]

impl<'a, Tag: ?Sized, Variant> Sync for SingletonTokenRefMut<'a, Tag, Variant> where
    Variant: Sync
[src]

impl<'a, Tag: ?Sized, Variant> Unpin for SingletonTokenRefMut<'a, Tag, Variant>[src]

impl<'a, Tag, Variant = SyncVariant> !UnwindSafe for SingletonTokenRefMut<'a, Tag, Variant>[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.