Skip to main content

RefCountInner

Struct RefCountInner 

Source
#[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 RefAny clones 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_void

Type-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: AtomicUsize

Number of RefAny instances sharing the same data. When this reaches 0, the data is deallocated.

§num_refs: AtomicUsize

Number of active shared borrows (Ref<T>). While > 0, mutable borrows are forbidden.

§num_mutable_refs: AtomicUsize

Number of active mutable borrows (RefMut<T>). While > 0, all other borrows are forbidden.

§_internal_len: usize

Size of the stored type in bytes (from size_of::<T>()).

§_internal_layout_size: usize

Layout size for deallocation (from Layout::size()).

§_internal_layout_align: usize

Required alignment for the stored type (from align_of::<T>()). CRITICAL: Must match the alignment used during allocation to prevent UB.

§type_id: u64

Runtime type identifier computed from TypeId::of::<T>(). Used to prevent invalid downcasts.

§type_name: AzString

Human-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: usize

Function 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: usize

Function 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§

Source§

impl Debug for RefCountInner

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.