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>
impl<T> RootedRc<T>
sourcepub fn downgrade(this: &Self, root: &Root) -> RootedRcWeak<T>
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.
sourcepub fn clone(&self, root: &Root) -> Self
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.
sourcepub fn into_inner(this: Self, root: &Root) -> Option<T>
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.
sourcepub fn explicit_drop_recursive(
self,
root: &Root,
param: &T::ExplicitDropParam,
) -> Option<T::ExplicitDropResult>where
T: ExplicitDrop,
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> ExplicitDrop for RootedRc<T>
impl<T> ExplicitDrop for RootedRc<T>
source§fn explicit_drop(
self,
root: &Self::ExplicitDropParam,
) -> Self::ExplicitDropResult
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.