pub struct ReadRef<'a, T: 'a, const N: usize> { /* private fields */ }
Expand description
A barely smart pointer referencing data owned by VLock
. The access
to the data is RAII-style, and is released when dropped.
This type is created by VLock::read
.
This type can’t be cloned. Holding on to a version for too long is no good.
Instead, call read
to acquire more copies if necessary. The next read
may return a newer version, however.
Trait Implementations§
Source§impl<T, const N: usize> Hash for ReadRef<'_, T, N>
impl<T, const N: usize> Hash for ReadRef<'_, T, N>
Source§fn hash<H: Hasher>(&self, state: &mut H)
fn hash<H: Hasher>(&self, state: &mut H)
Feeds the address of a pointer to calculate a hash, which is unique per version.
Dereference to hash the value behind the pointer.
§Examples
use std::collections::HashSet;
use vlock::VLock;
let lock: VLock<_, 2> = 10.into();
let mut ptr_set = HashSet::new();
let mut val_set = HashSet::new();
assert!(ptr_set.insert(lock.read()));
assert!(val_set.insert(*lock.read()));
assert!(!ptr_set.insert(lock.read()));
assert!(!val_set.insert(*lock.read()));
lock.update(|curr, value| *value = *curr, || 0);
assert!(ptr_set.insert(lock.read()));
assert!(!val_set.insert(*lock.read()));
Source§impl<T, const N: usize> PartialEq for ReadRef<'_, T, N>
impl<T, const N: usize> PartialEq for ReadRef<'_, T, N>
Source§fn eq(&self, other: &Self) -> bool
fn eq(&self, other: &Self) -> bool
Equality by comparing the addresses of two pointers, which if equal guarantee that two versions are in fact the same exact version.
Dereference to compare the inner values.
§Examples
use vlock::VLock;
let lock: VLock<_, 2> = 10.into();
let read1 = lock.read();
let read2 = lock.read();
assert_eq!(read1, read2);
lock.update(|curr, value| *value = *curr, || 0);
let read3 = lock.read();
assert_ne!(read2, read3);
assert_eq!(*read2, *read3);
impl<T, const N: usize> Eq for ReadRef<'_, T, N>
impl<T: Sync, const N: usize> Send for ReadRef<'_, T, N>
impl<T: Sync, const N: usize> Sync for ReadRef<'_, T, N>
Auto Trait Implementations§
impl<'a, T, const N: usize> Freeze for ReadRef<'a, T, N>
impl<'a, T, const N: usize> RefUnwindSafe for ReadRef<'a, T, N>where
T: RefUnwindSafe,
impl<'a, T, const N: usize> Unpin for ReadRef<'a, T, N>
impl<'a, T, const N: usize> UnwindSafe for ReadRef<'a, T, N>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more