Struct RootedRc

Source
pub struct RootedRc<T> { /* private fields */ }
Expand description

Analagous to std::rc::Rc. In particular like std::rc::Rc and unlike std::sync::Arc, it doesn’t perform any atomic operations internally, making it relatively inexpensive

Unlike std::rc::Rc, this type Send and Sync if T is. This is safe because the owner is required to prove ownership of the associated Root to perform any sensitive operations.

Instances must be destroyed explicitly, using RootedRc::explicit_drop, RootedRc::explicit_drop_recursive, or RootedRc::into_inner. These validate that the Root is held before manipulating reference counts, etc.

Dropping RootedRc without calling one of these methods results in a panic in debug builds, or leaking the object in release builds.

Implementations§

Source§

impl<T> RootedRc<T>

Source

pub fn new(root: &Root, val: T) -> Self

Creates a new object associated with root.

Source

pub fn downgrade(this: &Self, root: &Root) -> RootedRcWeak<T>

Create a weak reference.

We use fully qualified syntax here for consistency with Rc and Arc and to avoid name conflicts with T’s methods.

Source

pub fn clone(&self, root: &Root) -> Self

Like Clone::clone, but requires that the corresponding Root is held.

Intentionally named clone to shadow Self::deref()::clone().

Panics if root is not the associated Root.

Source

pub fn into_inner(this: Self, root: &Root) -> Option<T>

Drop the RootedRc, and return the inner value if this was the last strong reference.

Source

pub fn explicit_drop_recursive( self, root: &Root, param: &T::ExplicitDropParam, ) -> Option<T::ExplicitDropResult>
where T: ExplicitDrop,

Drops self, and if self was the last strong reference, call ExplicitDrop::explicit_drop on the internal value.

Trait Implementations§

Source§

impl<T> Deref for RootedRc<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl<T> ExplicitDrop for RootedRc<T>

Source§

fn explicit_drop( self, root: &Self::ExplicitDropParam, ) -> Self::ExplicitDropResult

If T itself implements ExplicitDrop, consider RootedRc::explicit_drop_recursive instead to call it when dropping the last strong reference.

Source§

type ExplicitDropParam = Root

Source§

type ExplicitDropResult = ()

Auto Trait Implementations§

§

impl<T> Freeze for RootedRc<T>

§

impl<T> !RefUnwindSafe for RootedRc<T>

§

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

§

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

§

impl<T> Unpin for RootedRc<T>

§

impl<T> !UnwindSafe for RootedRc<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
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> NoTypeInference for T

Source§

type This = T

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