[][src]Trait kul::drop::RcLikeAtomicCounts

pub trait RcLikeAtomicCounts: RcLike where
    Self::Target: Sized
{ fn counts(this: &Self) -> (usize, usize); fn try_replace_optim(
        this: &mut Self,
        val: Self::Target
    ) -> Result<Self::Target, Self::Target> { ... } }

Allows generically working with Datum reference types that wrap Rc-like types that can supply both strong and weak reference counts atomically. Currently, this is only Rc, but hopefully in the future Arc can be included as well if it can provide the ability to get both counts atomically. This could also be used for other, non-standard, types that meet the requirements.

Required methods

fn counts(this: &Self) -> (usize, usize)

Atomically gets the number of strong and weak pointers to the underlying value. I.e. gets a snapshot of the state of both the strong and weak counts at the same logical instant. In particular, when strong=1 and weak=0 this means either count cannot change after this function returns except via use of the only strong reference, and if you control that strong reference and do not change the counts, then you can depend on being able to get mutable access (e.g. via get_mut) to the underlying value, guaranteed.

Loading content...

Provided methods

fn try_replace_optim(
    this: &mut Self,
    val: Self::Target
) -> Result<Self::Target, Self::Target>

Optimized implementation of Algo1DatumRef::try_replace for generic Rc-like types that can supply both strong and weak reference counts atomically. The default implementation uses DerefTryMut when possible to avoid the heap allocation and unwrapping that the basic default RcLike::try_replace does.

Loading content...

Implementors

impl<TT, ET> RcLikeAtomicCounts for DatumRc<TT, ET>[src]

fn counts(this: &Self) -> (usize, usize)[src]

This is atomic enough to meet the requirements, because Rc is single-threaded.

fn try_replace_optim(
    this: &mut Self,
    val: Self::Target
) -> Result<Self::Target, Self::Target>
[src]

Loading content...