Skip to main content

AtomicRefCell

Struct AtomicRefCell 

Source
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>

Source

pub fn new(value: T) -> Self

Source

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.

Source

pub fn into_inner(self) -> T

Unwrap the value from the RefCell and kill it, returning the value.

Source

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.

Source

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.

Source

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>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Default> Default for AtomicRefCell<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: Send> Send for AtomicRefCell<T>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Component for T
where T: Send + Sync + 'static,