pub struct NanBox(/* private fields */);Expand description
A NaN-boxed value: 8 bytes encoding any VM value type.
Floats are stored as-is (their bit pattern). Non-float values are encoded in the NaN payload space.
Implementations§
Source§impl NanBox
impl NanBox
Sourcepub fn int(n: i64) -> Self
pub fn int(n: i64) -> Self
Create an integer value preserving the full i64 range.
Values that fit in 48 bits (sign-extended) take the inline
fast path — one tagged NaN, no allocation. Values outside
that range are boxed as HeapObject::BigInt so the full
i64 round-trips without precision loss.
This is the load-bearing contract for CppNix compatibility:
i64::MAX - 1 must round-trip exactly, otherwise any flake
containing large integer literals (timestamps, byte counts,
builtins.bitAnd over wide masks) would diverge.
Sourcepub fn heap(obj: HeapObject) -> Self
pub fn heap(obj: HeapObject) -> Self
Create a pointer to a heap-allocated object.
Sourcepub fn higher_order_builtin(h: HigherOrderBuiltin) -> Self
pub fn higher_order_builtin(h: HigherOrderBuiltin) -> Self
Create a higher-order builtin value (heap-allocated).
pub fn is_null(&self) -> bool
pub fn is_bool(&self) -> bool
pub fn is_int(&self) -> bool
pub fn is_ptr(&self) -> bool
Sourcepub fn as_int(&self) -> Option<i64>
pub fn as_int(&self) -> Option<i64>
Extract an integer. Returns None if not an int.
Handles both the inline 48-bit fast path AND the heap-boxed
BigInt fallback so the full i64 range round-trips.
Sourcepub fn as_heap(&self) -> Option<&HeapObject>
pub fn as_heap(&self) -> Option<&HeapObject>
Extract the heap object. Returns None if not a pointer.
Sourcepub fn type_name(&self) -> &'static str
pub fn type_name(&self) -> &'static str
Return the Nix type name for this value (mirrors VMValue::type_name).
Sourcepub fn is_truthy(&self) -> Result<bool, VMError>
pub fn is_truthy(&self) -> Result<bool, VMError>
Check if this value is truthy (for conditionals). Only booleans are valid; everything else is a type error.
Sourcepub fn is_closure(&self) -> bool
pub fn is_closure(&self) -> bool
Check if this is a closure.
Sourcepub fn is_builtin(&self) -> bool
pub fn is_builtin(&self) -> bool
Check if this is a builtin.
Sourcepub fn is_higher_order_builtin(&self) -> bool
pub fn is_higher_order_builtin(&self) -> bool
Check if this is a higher-order builtin.
Sourcepub fn as_string(&self) -> Option<&str>
pub fn as_string(&self) -> Option<&str>
Extract a string reference. Returns None if not a string.
Sourcepub fn as_list(&self) -> Option<&[NanBox]>
pub fn as_list(&self) -> Option<&[NanBox]>
Extract a list reference. Returns None if not a list.
Sourcepub fn as_attrs(&self) -> Option<&BTreeMap<Symbol, NanBox>>
pub fn as_attrs(&self) -> Option<&BTreeMap<Symbol, NanBox>>
Extract an attrs reference. Returns None if not an attrset.
Sourcepub fn as_closure(&self) -> Option<&VMClosure>
pub fn as_closure(&self) -> Option<&VMClosure>
Extract a closure reference. Returns None if not a closure.
Sourcepub fn as_builtin(&self) -> Option<&VMBuiltin>
pub fn as_builtin(&self) -> Option<&VMBuiltin>
Extract a builtin reference. Returns None if not a builtin.
Sourcepub fn as_thunk(&self) -> Option<&VMThunk>
pub fn as_thunk(&self) -> Option<&VMThunk>
Extract a thunk reference. Returns None if not a thunk.
Sourcepub fn as_higher_order_builtin(&self) -> Option<&HigherOrderBuiltin>
pub fn as_higher_order_builtin(&self) -> Option<&HigherOrderBuiltin>
Extract a higher-order builtin reference.
Sourcepub fn from_vmvalue(val: &VMValue) -> Self
pub fn from_vmvalue(val: &VMValue) -> Self
Convert a VMValue to a NanBox.
Sourcepub fn to_vmvalue(&self) -> VMValue
pub fn to_vmvalue(&self) -> VMValue
Convert a NanBox back to a VMValue.
Trait Implementations§
impl Eq for NanBox
Auto Trait Implementations§
impl Freeze for NanBox
impl RefUnwindSafe for NanBox
impl Send for NanBox
impl Sync for NanBox
impl Unpin for NanBox
impl UnsafeUnpin for NanBox
impl UnwindSafe for NanBox
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.