pub struct Shared<T> { /* private fields */ }Expand description
Single threaded shared value, a thin wrapper over Rc<RefCell<T>>.
Unlike RefCell directly, borrowing never panics: Shared::read and
Shared::write return None when the value is already borrowed the
other way.
Implementations§
Sourcepub fn try_consume(self) -> Result<T, Self>
pub fn try_consume(self) -> Result<T, Self>
Unwraps the value when this is the last reference, otherwise gives the handle back untouched.
Sourcepub fn read(&self) -> Option<Ref<'_, T>>
pub fn read(&self) -> Option<Ref<'_, T>>
Borrows the value immutably, or returns None when it is already
borrowed mutably.
Sourcepub fn write(&self) -> Option<RefMut<'_, T>>
pub fn write(&self) -> Option<RefMut<'_, T>>
Borrows the value mutably, or returns None when it is already
borrowed.
Sourcepub fn swap(&self, data: T) -> Option<T>
pub fn swap(&self, data: T) -> Option<T>
Replaces the value and returns the old one, or None when it is
already borrowed.
Sourcepub fn references_count(&self) -> usize
pub fn references_count(&self) -> usize
Returns how many handles point at this value.
Returns true when both handles point at the same value.
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Initialize for Twhere
T: Default,
impl<T> Initialize for Twhere
T: Default,
Source§fn initialize() -> T
fn initialize() -> T
Returns the initial value of this type.