pub struct ReadHandle<T> { /* private fields */ }
Expand description

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

Create a ReadHandleFactory which is Send & Sync and can be shared across threads to create additional ReadHandle instances.

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.

Returns true if the WriteHandle has been dropped.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.