pub struct AtomicRefCell<T> { /* private fields */ }Expand description
A RefCell implementation which is thread safe. This type performs all the standard runtime
borrow checking which would be familiar from using RefCell.
UnsafeCell is used in this type, but borrow checking is performed using atomic values,
garunteeing safe access across threads.
§Safety
Runtime borrow checking is only conducted in builds with debug_assertions enabled. Release
builds assume proper resource access and will cause undefined behavior with improper use.
Implementations§
Source§impl<T> AtomicRefCell<T>
impl<T> AtomicRefCell<T>
pub fn new(value: T) -> Self
Sourcepub fn get(&self) -> Ref<'_, T>
pub fn get(&self) -> Ref<'_, T>
Retrieve an immutable Ref wrapped reference of &T.
§Panics
This method panics if this value is already mutably borrowed.
§Safety
Runtime borrow checking is only conducted in builds with debug_assertions enabled. Release
builds assume proper resource access and will cause undefined behavior with improper use.
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Unwrap the value from the RefCell and kill it, returning the value.
Sourcepub fn try_get(&self) -> Result<Ref<'_, T>, String>
pub fn try_get(&self) -> Result<Ref<'_, T>, String>
Retrieve an immutable Ref wrapped reference of &T. This is the safe version of get
providing an error result on failure.
§Returns
Some(T) if the value can be retrieved.
Err if the value is already mutably borrowed.
Sourcepub fn get_mut(&self) -> RefMut<'_, T>
pub fn get_mut(&self) -> RefMut<'_, T>
Retrieve an mutable RefMut wrapped reference of &mut T.
§Panics
This method panics if this value is already mutably borrowed.
§Safety
Runtime borrow checking is only conducted in builds with debug_assertions enabled. Release
builds assume proper resource access and will cause undefined behavior with improper use.
Sourcepub fn try_get_mut(&self) -> Result<RefMut<'_, T>, String>
pub fn try_get_mut(&self) -> Result<RefMut<'_, T>, String>
Retrieve a mutable RefMut wrapped reference of &mut T. This is the safe version of
get_mut providing an error result on failure.
§Returns
Some(T) if the value can be retrieved.
Err if the value is already mutably borrowed.
§Safety
This release version of this function does not perform runtime borrow checking and will cause undefined behavior if borrow rules are violated. This means they should be enforced on the use of this type.
Trait Implementations§
Source§impl<T: Debug> Debug for AtomicRefCell<T>
impl<T: Debug> Debug for AtomicRefCell<T>
Source§impl<T: Default> Default for AtomicRefCell<T>
impl<T: Default> Default for AtomicRefCell<T>
impl<T: Send> Send for AtomicRefCell<T>
impl<T: Sync> Sync for AtomicRefCell<T>
Auto Trait Implementations§
impl<T> !Freeze for AtomicRefCell<T>
impl<T> !RefUnwindSafe for AtomicRefCell<T>
impl<T> Unpin for AtomicRefCell<T>where
T: Unpin,
impl<T> UnsafeUnpin for AtomicRefCell<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for AtomicRefCell<T>where
T: UnwindSafe,
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more