pub struct SharedCell<T> { /* private fields */ }Available on crate feature
std only.Expand description
Atomic shared version of OnceLock - backed by an Arc<RwLock<Option<T>>>.
let value = SharedCell::<bool>::empty(); // or default()
assert_eq!(None, value.take());
value.set(true);
assert_eq!(Some(true), value.take());
assert_eq!(None, value.take());Implementations§
Sourcepub fn as_ref(&self) -> ReadGuard<'_, T>
pub fn as_ref(&self) -> ReadGuard<'_, T>
Returns a shared (locked) reference to the inner object
Sourcepub fn peek_mut<V: FnMut(Option<&mut T>)>(&self, func: V)
pub fn peek_mut<V: FnMut(Option<&mut T>)>(&self, func: V)
Mutably peeks at the value, allows for edits.
Sourcepub fn as_mut(&self) -> WriteGuard<'_, T>
pub fn as_mut(&self) -> WriteGuard<'_, T>
Returns a mutable (locked) reference to the inner object.
Trait Implementations§
Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more