pub struct AccessCell<T> { /* private fields */ }Expand description
A cell holding a value of type T with re-entrant mutable access.
The first caller of access runs immediately; any further
calls to access from within that closure (or its queue) are enqueued and
executed in order after the current work completes.
Thread-safe: safe to share across threads and use from multiple threads.
Implementations§
Source§impl<T> AccessCell<T>
impl<T> AccessCell<T>
Sourcepub fn access(&self, f: impl FnOnce(&mut T) + Send + 'static)
pub fn access(&self, f: impl FnOnce(&mut T) + Send + 'static)
Runs f with exclusive mutable access to the inner value.
If called while another access closure is running (re-entrant or from
another thread), f is queued and run after the current closure and
any other queued closures finish.
The closure must be Send so it can be moved into the queue when called
from another thread.
Sourcepub fn access_ref(&self) -> RwLockReadGuard<'_, T>
pub fn access_ref(&self) -> RwLockReadGuard<'_, T>
Returns an immutable reference to the inner value.
Blocks if an access closure is currently running. Safe to call from
any thread.