Skip to main content

SharedCell

Struct SharedCell 

Source
pub struct SharedCell<T>(/* private fields */);
Expand description

Strong, shared ownership of T with interior mutability.

Implementations§

Source§

impl<T> SharedCell<T>

Source

pub fn new(value: T) -> Self

Wraps a value inside Rc<RefCell<..>>.

Source

pub fn downgrade(&self) -> WeakCell<T>

Creates a WeakCell pointing to the same allocation.

Source

pub fn borrow(&self) -> Ref<'_, T>

Immutable borrow of the inner value.

Source

pub fn borrow_mut(&self) -> RefMut<'_, T>

Mutable borrow of the inner value.

Source

pub fn try_borrow(&self) -> Result<Ref<'_, T>, BorrowError>

Attempts to immutably borrow the inner value.

§Errors

Returns BorrowError if the value is currently mutably borrowed.

Source

pub fn try_borrow_mut(&self) -> Result<RefMut<'_, T>, BorrowMutError>

Attempts to mutably borrow the inner value.

§Errors

Returns BorrowMutError if the value is currently borrowed (mutably or immutably).

Source

pub fn strong_count(&self) -> usize

Number of active strong references.

Source

pub fn weak_count(&self) -> usize

Number of active weak references.

Source

pub fn as_ptr(&self) -> *const RefCell<T>

Returns the raw pointer to the underlying cell, useful for identity diagnostics.

Source

pub fn with<R>(&self, f: impl FnOnce(&T) -> R) -> R

Runs f against an immutable borrow of the inner value, returning its result.

The borrow is dropped at the end of the closure, so callers can safely follow the call with operations that re-enter the same cell (e.g. event dispatch).

Source

pub fn with_mut<R>(&self, f: impl FnOnce(&mut T) -> R) -> R

Runs f against a mutable borrow of the inner value, returning its result.

The borrow is dropped at the end of the closure, so callers can safely follow the call with operations that re-enter the same cell.

Trait Implementations§

Source§

impl<T> Clone for SharedCell<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for SharedCell<T>

Source§

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

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

impl<T> Deref for SharedCell<T>

Source§

type Target = Rc<RefCell<T>>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T> Eq for SharedCell<T>

Source§

impl<T> From<Rc<RefCell<T>>> for SharedCell<T>

Source§

fn from(inner: Rc<RefCell<T>>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<SharedCell<T>> for Rc<RefCell<T>>

Source§

fn from(shared: SharedCell<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> Hash for SharedCell<T>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Hashes the cell’s pointer address, consistent with the identity-based PartialEq impl.

1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T> PartialEq for SharedCell<T>

Source§

fn eq(&self, other: &Self) -> bool

Identity equality: two handles compare equal when they point to the same cell.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for SharedCell<T>

§

impl<T> !Send for SharedCell<T>

§

impl<T> !Sync for SharedCell<T>

§

impl<T> !UnwindSafe for SharedCell<T>

§

impl<T> Freeze for SharedCell<T>

§

impl<T> Unpin for SharedCell<T>

§

impl<T> UnsafeUnpin for SharedCell<T>

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.