rcell

Enum RCell

Source
pub enum RCell<T> {
    Strong(Arc<T>),
    Weak(Weak<T>),
    Empty,
}
Expand description

A RCell holding either an Strong<T>, a Weak<T> or being Empty.

Variants§

§

Strong(Arc<T>)

Strong reference

§

Weak(Weak<T>)

Weak reference

§

Empty

Empty cell

Implementations§

Source§

impl<T> RCell<T>

Source

pub fn new(value: T) -> Self

Creates a new strong (Strong) RCell from the supplied value.

Source

pub fn retained(&self) -> bool

Returns ‘true’ when this RCell contains a Strong<T>.

Source

pub fn refcount(&self) -> usize

Returns the number of strong references holding an object alive. The returned strong count is informal only, the result may be approximate and has race conditions when other threads modify the reference count concurrently.

Source

pub fn retain(&mut self) -> Option<Strong<T>>

Tries to upgrade this RCell from Weak to Strong. This means that as long the RCell is not dropped the associated data won’t be either. When successful it returns Some<Strong> containing the value, otherwise None is returned on failure.

Source

pub fn release(&mut self)

Downgrades the RCell, any associated value may become dropped when no other references exist. When no strong reference left remaining this cell becomes Empty.

Source

pub fn remove(&mut self)

Removes the reference to the value. The rationale for this function is to release any resource associated with a RCell (potentially member of a struct that lives longer) in case one knows that it will never be upgraded again.

Source

pub fn request(&self) -> Option<Strong<T>>

Tries to get an Strong<T> from the RCell. This may fail if the RCell was Weak and all other strong references became dropped.

Trait Implementations§

Source§

impl<T: Debug> Debug for RCell<T>

Source§

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

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

impl<T> Default for RCell<T>

Source§

fn default() -> Self

Creates an RCell that doesn’t hold any reference.

Source§

impl<T> From<Arc<T>> for RCell<T>

Source§

fn from(strong: Strong<T>) -> Self

Creates a new strong RCell with the supplied Strong<T>.

Source§

impl<T> From<Weak<T>> for RCell<T>

Source§

fn from(weak: Weak<T>) -> Self

Creates a new weak RCell with the supplied Weak<T>.

Source§

impl<T> Replace<Arc<T>> for RCell<T>

Source§

fn replace(&mut self, strong: Strong<T>)

Replaces the RCell with the supplied Strong<T>. The old entry becomes dropped.

Source§

impl<T> Replace<Weak<T>> for RCell<T>

Source§

fn replace(&mut self, weak: Weak<T>)

Replaces the RCell with the supplied Weak<T>. The old entry becomes dropped.

Auto Trait Implementations§

§

impl<T> Freeze for RCell<T>

§

impl<T> RefUnwindSafe for RCell<T>
where T: RefUnwindSafe,

§

impl<T> Send for RCell<T>
where T: Sync + Send,

§

impl<T> Sync for RCell<T>
where T: Sync + Send,

§

impl<T> Unpin for RCell<T>

§

impl<T> UnwindSafe for RCell<T>
where T: RefUnwindSafe,

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, 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, 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.