Skip to main content

RefCount

Struct RefCount 

Source
pub struct RefCount { /* private fields */ }
Expand description

Reference count using state layout with LEAKED and IMMORTAL support.

State layout (usize): 64-bit: [destructed] [published] [leaked] [immortal] [60 bits: strong_count] 32-bit: [destructed] [published] [leaked] [immortal] [28 bits: strong_count]

See [IMMORTAL] for what the immortal bit promises.

Implementations§

Source§

impl RefCount

Source

pub fn new() -> Self

Create a new RefCount with strong count = 1

Source

pub fn get(&self) -> usize

Get current strong count

Source

pub fn is_immortal(&self) -> bool

Whether this object lives for the whole process.

A plain relaxed load: the bit is sticky and is set before the object is shared, so no reader can observe it flipping.

Source

pub fn inc(&self)

Increment strong count

Source

pub fn inc_by(&self, n: usize)

Source

pub fn safe_inc(&self) -> bool

Returns true if successful

Source

pub fn dec(&self) -> bool

Decrement strong count. Returns true when count drops to 0.

Source

pub fn leak(&self)

Mark this object as leaked (interned). It will never be deallocated.

This also makes the object immortal, and RefCount::dec depends on that: leaked and immortal are separate answers — is_leaked means “the string pool owns this copy” and is what pointer-equality key lookups read — but every leaked object is immortal, so dec can decide both from the immortal bit alone.

Source

pub fn make_immortal(&self)

Make this object immortal: every later inc/dec becomes a branch and the object is never deallocated. See [IMMORTAL] for the invariant.

Idempotent, and safe to call on an object that is already interned — the other flags are preserved.

Source

pub fn is_leaked(&self) -> bool

Check if this object is leaked (interned).

Source

pub fn mark_published(&self)

Mark the object as published to a lock-free cache (sticky).

Source

pub fn is_published(&self) -> bool

Trait Implementations§

Source§

impl Default for RefCount

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> ErasedDestructor for T
where T: 'static,

Source§

impl<T, U> ExactFrom<T> for U
where U: TryFrom<T>,

Source§

fn exact_from(value: T) -> U

Source§

impl<T, U> ExactInto<U> for T
where U: ExactFrom<T>,

Source§

fn exact_into(self) -> U

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> ImaginaryInto<U> for T
where U: ImaginaryFrom<T>,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> OverflowingInto<U> for T
where U: OverflowingFrom<T>,

Source§

impl<T> PrimitiveIntRandomBounds for T

Source§

impl<T> PrimitiveSignedRandomBounds for T

Source§

impl<T, U> RoundingInto<U> for T
where U: RoundingFrom<T>,

Source§

impl<T, U> SaturatingInto<U> for T
where U: SaturatingFrom<T>,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T, U> WrappingInto<U> for T
where U: WrappingFrom<T>,

Source§

fn wrapping_into(self) -> U