Type Definition tokenlock::UnsyncSingletonToken[][src]

type UnsyncSingletonToken<Tag> = SingletonToken<Tag, UnsyncVariant>;

The !Sync variant of SingletonToken.

Examples

use std::{cell::Cell, thread::spawn};
struct MyTag;
impl_singleton_token_factory!(MyTag);

type MyTokenLock<T> = UnsyncTokenLock<T, SingletonTokenId<MyTag>>;
type MyToken = UnsyncSingletonToken<MyTag>;
type MyTokenId = SingletonTokenId<MyTag>;

static LOCK1: MyTokenLock<Cell<u32>> =
    MyTokenLock::new(MyTokenId::new(), Cell::new(1));

// Create a singleton token with a runtime uniqueness check
let mut token = MyToken::new().unwrap();

spawn(move || {
    // Shared references can alias
    let (token_1, token_2) = (token.borrow(), token.borrow());

    LOCK1.read(&*token_1).set(2);
    LOCK1.read(&*token_2).set(4);
});

Implementations

impl<Tag: ?Sized> UnsyncSingletonToken<Tag>[src]

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.

impl<Tag: ?Sized> UnsyncSingletonToken<Tag>[src]

pub const fn into_sync(self) -> SingletonToken<Tag>[src]

Convert UnsyncSingletonToken to the Sync variant.

Trait Implementations

impl<Tag: ?Sized> Unsync for UnsyncSingletonToken<Tag>[src]