Struct tokenlock::SingletonTokenRef [−][src]
Zero-sized logical equivalent of &'a
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 token = SingletonToken::<MyTag>::new().unwrap(); let lock = TokenLock::new(token.id(), 1); // `SingletonTokenRef` is zero-sized (unlike `&SingletonToken`), so there is // no runtime overhead involved with passing `SingletonTokenRef`. access_lock(token.borrow(), &lock); fn access_lock( token: SingletonTokenRef<'_, MyTag>, lock: &TokenLock<u32, SingletonTokenId<MyTag>>, ) { assert_eq!(*lock.read(&*token), 1); }
SingletonTokenRef
does not allow mutable borrow:
ⓘ
let token_ref: SingletonTokenRef<MyTag> = token.borrow(); // compile error: `SingletonTokenRef` does not implement `DerefMut` *lock.write(&mut *token_ref) = 4;
SingletonTokenRef
is Send
-able because SingletonToken
is Sync
:
let token: &'static SingletonTokenGuard<MyTag> = Box::leak(Box::new(SingletonToken::<MyTag>::new().unwrap())); let token_ref: SingletonTokenRef<MyTag> = token.borrow(); 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_sync(&self) -> SingletonTokenRef<'_, Tag>
[src]
Borrow self: UnsyncSingletonToken
as SingletonTokenRef
.
Trait Implementations
impl<Tag: ?Sized, Variant: SingletonTokenVariant> Debug for SingletonTokenRef<'_, Tag, Variant>
[src]
impl<Tag: ?Sized, Variant: SingletonTokenVariant> Deref for SingletonTokenRef<'_, Tag, Variant>
[src]
type Target = SingletonToken<Tag, Variant>
The resulting type after dereferencing.
fn deref(&self) -> &Self::Target
[src]
impl<Tag: ?Sized, Variant: SingletonTokenVariant> Eq for SingletonTokenRef<'_, Tag, Variant>
[src]
impl<Tag: ?Sized, Variant: SingletonTokenVariant> Hash for SingletonTokenRef<'_, Tag, Variant>
[src]
fn hash<H: Hasher>(&self, _: &mut H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<Tag: ?Sized, Variant: SingletonTokenVariant> PartialEq<SingletonTokenRef<'_, Tag, Variant>> for SingletonTokenRef<'_, Tag, Variant>
[src]
Auto Trait Implementations
impl<'a, Tag: ?Sized, Variant> RefUnwindSafe for SingletonTokenRef<'a, Tag, Variant> where
Variant: RefUnwindSafe,
[src]
Variant: RefUnwindSafe,
impl<'a, Tag: ?Sized, Variant> Send for SingletonTokenRef<'a, Tag, Variant> where
Variant: Sync,
[src]
Variant: Sync,
impl<'a, Tag: ?Sized, Variant> Sync for SingletonTokenRef<'a, Tag, Variant> where
Variant: Sync,
[src]
Variant: Sync,
impl<'a, Tag: ?Sized, Variant> Unpin for SingletonTokenRef<'a, Tag, Variant>
[src]
impl<'a, Tag: ?Sized, Variant> UnwindSafe for SingletonTokenRef<'a, Tag, Variant> where
Variant: RefUnwindSafe,
[src]
Variant: RefUnwindSafe,
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>,