pub struct ValueSlot(/* private fields */);Expand description
A raw 8-byte value slot for TypedObject field storage.
Implementations§
Source§impl ValueSlot
impl ValueSlot
Sourcepub fn from_typed_scalar(ts: TypedScalar) -> (Self, bool)
pub fn from_typed_scalar(ts: TypedScalar) -> (Self, bool)
Create a ValueSlot from a TypedScalar.
Returns (slot, is_heap) — is_heap is always false for scalars
since all scalar values fit in 8 bytes without heap allocation.
Source§impl ValueSlot
impl ValueSlot
Sourcepub fn from_number(n: f64) -> Self
pub fn from_number(n: f64) -> Self
Store a f64 as raw IEEE 754 bits.
Sourcepub fn from_int(i: i64) -> Self
pub fn from_int(i: i64) -> Self
Store an i64 as raw two’s complement bits. Full 64-bit range, no precision loss.
Sourcepub fn from_u64(v: u64) -> Self
pub fn from_u64(v: u64) -> Self
Store a u64 directly. Only meaningful when the FieldType is known to be U64.
Sourcepub fn from_heap(value: HeapValue) -> Self
pub fn from_heap(value: HeapValue) -> Self
Store any HeapValue on the heap. The caller MUST set the corresponding
bit in heap_mask so Drop knows to free this.
Without gc feature: allocates via Box (freed by drop_heap).
With gc feature: allocates via GcHeap (freed by garbage collector).
Sourcepub fn as_heap_value(&self) -> &HeapValue
pub fn as_heap_value(&self) -> &HeapValue
Read as heap HeapValue reference (caller must know this slot is a heap pointer). Returns a reference to the pointed-to HeapValue.
Sourcepub fn as_heap_nb(&self) -> ValueWord
pub fn as_heap_nb(&self) -> ValueWord
Create a ValueWord directly from this heap slot (no intermediate conversion). Caller must know this slot is a heap pointer.
Sourcepub fn from_value_word(nb: &ValueWord) -> (Self, bool)
pub fn from_value_word(nb: &ValueWord) -> (Self, bool)
Store a ValueWord losslessly. For inline types (f64, i48, bool,
none, unit, function, module_function), stores the raw NaN-boxed tag bits
directly. For heap-tagged values, clones the HeapValue into a new Box.
Returns (slot, is_heap) — caller must set the heap_mask bit if is_heap.
Sourcepub fn from_nanboxed(nb: &ValueWord) -> (Self, bool)
pub fn from_nanboxed(nb: &ValueWord) -> (Self, bool)
Backward-compatibility alias.
Sourcepub fn as_value_word(&self, is_heap: bool) -> ValueWord
pub fn as_value_word(&self, is_heap: bool) -> ValueWord
Reconstruct a ValueWord from this slot. is_heap must match the value
returned by from_value_word (i.e., whether heap_mask bit is set).
Sourcepub fn as_nanboxed(&self, is_heap: bool) -> ValueWord
pub fn as_nanboxed(&self, is_heap: bool) -> ValueWord
Backward-compatibility alias.
Sourcepub unsafe fn drop_heap(&mut self)
pub unsafe fn drop_heap(&mut self)
Drop the heap value. MUST only be called on heap slots.
Without gc feature: frees via Box deallocation.
With gc feature: no-op (GC handles deallocation).
§Safety
Caller must ensure this slot actually contains a valid heap pointer.
Sourcepub unsafe fn clone_heap(&self) -> Self
pub unsafe fn clone_heap(&self) -> Self
Clone a heap slot by cloning the pointed-to HeapValue into a new Box.
Without gc feature: deep clones into a new Box allocation.
With gc feature: bitwise copy (GC tracks all references).
§Safety
Caller must ensure this slot actually contains a valid heap pointer.