#[repr(C)]pub struct RefCount {
pub ptr: *const RefCountInner,
pub run_destructor: bool,
}Expand description
Wrapper around a heap-allocated RefCountInner.
This is the shared metadata that all RefAny clones point to.
The RefCount is responsible for all memory management:
RefCount::clone()incrementsnum_copiesin RefCountInnerRefCount::drop()decrementsnum_copiesand, if it reaches 0:- Frees the RefCountInner
- Calls the custom destructor on the data
- Deallocates the data memory
§Why run_destructor: bool
This flag tracks whether this RefCount instance should decrement
num_copies when dropped. Set to true for all clones (including
those created by RefAny::clone() and AZ_REFLECT macros).
Set to false after the decrement has been performed to prevent
double-decrement.
Fields§
§ptr: *const RefCountInner§run_destructor: boolImplementations§
Source§impl RefCount
impl RefCount
Sourcepub fn debug_get_refcount_copied(&self) -> RefCountInnerDebug
pub fn debug_get_refcount_copied(&self) -> RefCountInnerDebug
Creates a debug snapshot of the current reference counts.
Loads all atomic values with SeqCst ordering to get a consistent view.
Runtime check: can we create a shared borrow?
Returns true if there are no active mutable borrows.
Multiple shared borrows can coexist (like &T in Rust).
§Memory Ordering
Uses SeqCst to ensure we see the most recent state from all threads.
If another thread just released a mutable borrow, we’ll see it.
Runtime check: can we create a mutable borrow?
Returns true only if there are ZERO active borrows of any kind.
This enforces Rust’s exclusive mutability rule (like &mut T).
§Memory Ordering
Uses SeqCst to ensure we see all recent borrows from all threads.
Both counters must be checked atomically to prevent races.
Sourcepub fn increase_ref(&self)
pub fn increase_ref(&self)
Increments the shared borrow counter.
Called when a Ref<T> is created. The Ref::drop will decrement it.
§Memory Ordering
SeqCst ensures this increment is visible to all threads before they
try to acquire a mutable borrow (which checks this counter).
Sourcepub fn decrease_ref(&self)
pub fn decrease_ref(&self)
Decrements the shared borrow counter.
Called when a Ref<T> is dropped, indicating the borrow is released.
§Memory Ordering
SeqCst ensures this decrement is immediately visible to other threads
waiting to acquire a mutable borrow.
Sourcepub fn increase_refmut(&self)
pub fn increase_refmut(&self)
Increments the mutable borrow counter.
Called when a RefMut<T> is created. Should only succeed when this
counter and num_refs are both 0.
§Memory Ordering
SeqCst ensures this increment is visible to all other threads,
blocking them from acquiring any borrow (shared or mutable).
Sourcepub fn decrease_refmut(&self)
pub fn decrease_refmut(&self)
Decrements the mutable borrow counter.
Called when a RefMut<T> is dropped, releasing exclusive access.
§Memory Ordering
SeqCst ensures this decrement is immediately visible, allowing
other threads to acquire borrows.
Trait Implementations§
Source§impl Clone for RefCount
impl Clone for RefCount
Source§fn clone(&self) -> Self
fn clone(&self) -> Self
Clones the RefCount and increments the reference count.
§Safety
This is safe because:
- The ptr is valid (created from Box::into_raw)
- num_copies is atomically incremented with SeqCst ordering
- This ensures the RefCountInner is not freed while clones exist
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Ord for RefCount
impl Ord for RefCount
Source§impl PartialOrd for RefCount
impl PartialOrd for RefCount
impl Eq for RefCount
impl StructuralPartialEq for RefCount
Auto Trait Implementations§
impl Freeze for RefCount
impl RefUnwindSafe for RefCount
impl !Send for RefCount
impl !Sync for RefCount
impl Unpin for RefCount
impl UnwindSafe for RefCount
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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