pub struct Wrrm<T> { /* private fields */ }Expand description
“Write-rarely-read-many” wrapper.
§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§
Source§impl<T> Wrrm<T>
impl<T> Wrrm<T>
Sourcepub fn modify_with(&self, modification: impl FnMut(&mut T))where
T: Clone,
pub fn modify_with(&self, modification: impl FnMut(&mut T))where
T: Clone,
Modifies the value using the given function.
The function will be passed a mutable reference to a copy of the value currently stored in the container.
Note: The function might be called multiple times, with new copies every time, in situations where multiple threads are competing for an update. You are expected to perform the same modification on the value every time.