[−][src]Struct wrrm::Wrrm
"Write-rarely-read-many" wrapper.
This lock-free container is suitable in situations where you perform a lot of reads to a T,
but only rarely modify that T.
From a logic point of view, it is more or less the equivalent of an RwLock, except that:
- It works in
no_stdplatforms. - Reading the
Talways takes the same time and will never wait for a lock to be released. - Writing the
Tis done in a compare-and-swap way, and updates might have to be performed multiple times.
Implementation details
This container contains more or less the equivalent of an Atomic<Arc<T>>. Accessing T is
quite cheap, as it only consists in cloning the Arc. Modifying T can be done by performing
a deep clone of T, then storing a pointer to the updated version in the Atomic.
If N threads try to update the T at the same time, the entire update of T might need to
be performed more than N times.
For example, if two threads try to update T at the same time, one of them will win and
perform the update. When trying to apply its own update, the other thread will detect that
the T has been touched in-between and will restart its own update from scratch.
Implementations
impl<T> Wrrm<T>[src]
pub fn new(value: T) -> Self[src]
Creates a new Wrrm.
pub fn access(&self) -> Access<T>[src]
Grants shared access to the content.
This Access struct will always point to the same, potentially stale, version. In other
words, if the content of the Wrrm is updated while an Access is alive, this
Access will still point to the old version.
pub fn modify_with(&self, modification: impl FnMut(&mut T)) where
T: Clone, [src]
T: Clone,
Modifies the value using the given function.
Important: The function might be called multiple times.
Trait Implementations
impl<T> Debug for Wrrm<T> where
T: Debug, [src]
T: Debug,
impl<T: Default> Default for Wrrm<T>[src]
impl<T> From<T> for Wrrm<T>[src]
Auto Trait Implementations
impl<T> Send for Wrrm<T> where
T: Send + Sync,
T: Send + Sync,
impl<T> Sync for Wrrm<T> where
T: Send + Sync,
T: Send + Sync,
impl<T> Unpin for Wrrm<T>
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,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<!> for 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.
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>,