Struct left_right::ReadHandle[][src]

pub struct ReadHandle<T> { /* fields omitted */ }

A read handle to a left-right guarded data structure.

To use a handle, first call enter to acquire a ReadGuard. This is similar to acquiring a Mutex, except that no exclusive lock is taken. All reads of the underlying data structure can then happen through the ReadGuard (which implements Deref<Target = T>).

Reads through a ReadHandle only see the changes up until the last time WriteHandle::publish was called. That is, even if a writer performs a number of modifications to the underlying data, those changes are not visible to reads until the writer calls publish.

ReadHandle is not Sync, which means that you cannot share a ReadHandle across many threads. This is because the coordination necessary to do so would significantly hamper the scalability of reads. If you had many reads go through one ReadHandle, they would need to coordinate among themselves for every read, which would lead to core contention and poor multi-core performance. By having ReadHandle not be Sync, you are forced to keep a ReadHandle per reader, which guarantees that you do not accidentally ruin your performance.

You can create a new, independent ReadHandle either by cloning an existing handle or by using a ReadHandleFactory. Note, however, that creating a new handle through either of these mechanisms does take a lock, and may therefore become a bottleneck if you do it frequently.

Implementations

impl<T> ReadHandle<T>[src]

pub fn enter(&self) -> Option<ReadGuard<'_, T>>[src]

Take out a guarded live reference to the read copy of the T.

While the guard lives, the WriteHandle cannot proceed with a call to WriteHandle::publish, so no queued operations will become visible to any reader.

If the WriteHandle has been dropped, this function returns None.

pub fn was_dropped(&self) -> bool[src]

Returns true if the WriteHandle has been dropped.

pub fn raw_handle(&self) -> Option<NonNull<T>>[src]

Returns a raw pointer to the read copy of the data.

Note that it is only safe to read through this pointer if you know that the writer will not start writing into it. This is most likely only the case if you are calling this method from inside a method that holds &mut WriteHandle.

Casting this pointer to &mut is never safe.

Trait Implementations

impl<T> Clone for ReadHandle<T>[src]

fn clone(&self) -> Self[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<T> Debug for ReadHandle<T>[src]

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

Formats the value using the given formatter. Read more

impl<T> Drop for ReadHandle<T>[src]

fn drop(&mut self)[src]

Executes the destructor for this type. Read more

impl<T> Send for ReadHandle<T> where
    T: Sync
[src]

Auto Trait Implementations

impl<T> !RefUnwindSafe for ReadHandle<T>

impl<T> !Sync for ReadHandle<T>

impl<T> Unpin for ReadHandle<T>

impl<T> UnwindSafe for ReadHandle<T> where
    T: RefUnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

Creates owned data from borrowed data, usually by cloning. Read more

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

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.

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

Performs the conversion.

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.

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

Performs the conversion.