Struct ReadRef

Source
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> AsRef<T> for ReadRef<'_, T, N>

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T, const N: usize> Borrow<T> for ReadRef<'_, T, N>

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T: Debug, const N: usize> Debug for ReadRef<'_, T, N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, const N: usize> Deref for ReadRef<'_, T, N>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &T

Dereferences the value.
Source§

impl<T: Display, const N: usize> Display for ReadRef<'_, T, N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, const N: usize> Drop for ReadRef<'_, T, N>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T, const N: usize> Hash for ReadRef<'_, T, N>

Source§

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()));
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T, const N: usize> PartialEq for ReadRef<'_, T, N>

Source§

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);
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, const N: usize> Pointer for ReadRef<'_, T, N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, const N: usize> Eq for ReadRef<'_, T, N>

Source§

impl<T: Sync, const N: usize> Send for ReadRef<'_, T, N>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.