#[repr(C)]pub struct RefCountInner {
pub _internal_ptr: *const c_void,
pub num_copies: AtomicUsize,
pub num_refs: AtomicUsize,
pub num_mutable_refs: AtomicUsize,
pub _internal_len: usize,
pub _internal_layout_size: usize,
pub _internal_layout_align: usize,
pub type_id: u64,
pub type_name: AzString,
pub custom_destructor: extern "C" fn(*mut c_void),
pub serialize_fn: usize,
pub deserialize_fn: usize,
}Expand description
Internal reference counting metadata for RefAny.
This struct tracks:
- How many
RefAnyclones exist (num_copies) - How many shared borrows are active (
num_refs) - How many mutable borrows are active (
num_mutable_refs) - Memory layout information for correct deallocation
- Type information for runtime type checking
§Thread Safety
All counters are AtomicUsize with SeqCst ordering, making them safe to access
from multiple threads simultaneously. The strong ordering ensures no thread can
observe inconsistent states (e.g., both seeing count=1 during final drop).
Fields§
§_internal_ptr: *const c_voidType-erased pointer to heap-allocated data.
SAFETY: Must be properly aligned for the stored type (guaranteed by
Layout::from_size_align in new_c). Never null for non-ZST types.
This pointer is shared by all RefAny clones, so replace_contents updates are visible to all clones.
num_copies: AtomicUsizeNumber of RefAny instances sharing the same data.
When this reaches 0, the data is deallocated.
num_refs: AtomicUsizeNumber of active shared borrows (Ref<T>).
While > 0, mutable borrows are forbidden.
num_mutable_refs: AtomicUsizeNumber of active mutable borrows (RefMut<T>).
While > 0, all other borrows are forbidden.
_internal_len: usizeSize of the stored type in bytes (from size_of::<T>()).
_internal_layout_size: usizeLayout size for deallocation (from Layout::size()).
_internal_layout_align: usizeRequired alignment for the stored type (from align_of::<T>()).
CRITICAL: Must match the alignment used during allocation to prevent UB.
type_id: u64Runtime type identifier computed from TypeId::of::<T>().
Used to prevent invalid downcasts.
type_name: AzStringHuman-readable type name (e.g., “MyStruct”) for debugging.
custom_destructor: extern "C" fn(*mut c_void)Function pointer to correctly drop the type-erased data. SAFETY: Must be called with a pointer to data of the correct type.
serialize_fn: usizeFunction pointer to serialize RefAny to JSON (0 = not set). Cast to RefAnySerializeFnType (defined in azul_layout::json) when called. Type: extern “C” fn(RefAny) -> Json
deserialize_fn: usizeFunction pointer to deserialize JSON to new RefAny (0 = not set). Cast to RefAnyDeserializeFnType (defined in azul_layout::json) when called. Type: extern “C” fn(Json) -> ResultRefAnyString
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for RefCountInner
impl RefUnwindSafe for RefCountInner
impl !Send for RefCountInner
impl !Sync for RefCountInner
impl Unpin for RefCountInner
impl UnwindSafe for RefCountInner
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> 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