euv-core 0.48.3

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
use super::*;

/// Returns `true` when type `T` fits inline inside the 24-byte, 8-byte-aligned SBO buffer.
///
/// # Returns
///
/// - `bool` - `true` when `size_of::<T>() <= 24` and `align_of::<T>() <= 8`.
#[must_use]
#[inline(always)]
pub(crate) const fn is_sbo_inline<T>() -> bool {
    size_of::<T>() <= SBO_INLINE_SIZE && align_of::<T>() <= SBO_INLINE_ALIGN
}

/// Returns the runtime `TypeId` of concrete type `T` for `SignalVTable` dispatch.
///
/// # Returns
///
/// - `TypeId` - Type identifier of `T`.
#[must_use]
pub(crate) fn sbo_type_id<T>() -> TypeId
where
    T: 'static,
{
    TypeId::of::<T>()
}

/// Drops an initialized concrete value `T` stored inside `storage` (inline or heap-spilled).
///
/// # Arguments
///
/// - `*mut SboStorage` - Exclusive pointer to initialized storage holding `T` or `*mut T`.
pub(crate) unsafe fn sbo_drop_value<T>(storage: *mut SboStorage)
where
    T: 'static,
{
    if is_sbo_inline::<T>() {
        // SAFETY: Caller guarantees `storage` holds an initialized inline `T` and owns it exclusively.
        unsafe {
            drop_in_place(storage.cast::<T>());
        }
    } else {
        // SAFETY: Caller guarantees `storage` holds a valid `Box::into_raw` `*mut T` pointer.
        unsafe {
            let boxed_ptr: *mut T = storage.cast::<*mut T>().read();
            drop(Box::from_raw(boxed_ptr));
        }
    }
}