NanBoxedValue

Struct NanBoxedValue 

Source
pub struct NanBoxedValue(/* private fields */);
Expand description

An 8-byte NaN-boxed value

This is the core type for the NaN-boxing optimization. All Seq values are encoded into exactly 8 bytes.

Implementations§

Source§

impl NanBoxedValue

Source

pub fn is_float(self) -> bool

Check if this value is a float (not in the NaN-box range)

Source

pub fn is_boxed(self) -> bool

Check if this value is a boxed (non-float) value

Source

pub fn tag(self) -> u8

Get the type tag (only valid if is_boxed() is true)

Source

pub fn payload(self) -> u64

Get the 47-bit payload (only valid if is_boxed() is true)

Source

pub fn is_int(self) -> bool

Check if this is an Int

Source

pub fn is_bool(self) -> bool

Check if this is a Bool

Source

pub fn is_string(self) -> bool

Check if this is a String

Source

pub fn is_symbol(self) -> bool

Check if this is a Symbol

Source

pub fn is_variant(self) -> bool

Check if this is a Variant

Source

pub fn is_map(self) -> bool

Check if this is a Map

Source

pub fn is_quotation(self) -> bool

Check if this is a Quotation

Source

pub fn is_closure(self) -> bool

Check if this is a Closure

Source

pub fn is_channel(self) -> bool

Check if this is a Channel

Source

pub fn is_weave_ctx(self) -> bool

Check if this is a WeaveCtx

Source

pub fn from_float(f: f64) -> Self

Create a NaN-boxed float

If the float is NaN, it’s canonicalized to avoid collision with boxed values.

Source

pub fn from_int(n: i64) -> Self

Create a NaN-boxed integer

§Panics

Panics if the integer is outside the 47-bit signed range.

Source

pub fn try_from_int(n: i64) -> Option<Self>

Create a NaN-boxed integer, returning None if out of range

Source

pub fn from_bool(b: bool) -> Self

Create a NaN-boxed boolean

Source

pub fn from_string_ptr(ptr: *const SeqString) -> Self

Create a NaN-boxed string pointer

§Safety

The pointer must be valid and properly aligned.

Source

pub fn from_symbol_ptr(ptr: *const SeqString) -> Self

Create a NaN-boxed symbol pointer

§Safety

The pointer must be valid and properly aligned.

Source

pub fn from_variant_ptr(ptr: *const Arc<VariantData>) -> Self

Create a NaN-boxed variant pointer

Source

pub fn from_map_ptr(ptr: *const Box<HashMap<MapKey, Value>>) -> Self

Create a NaN-boxed map pointer

Source

pub fn from_quotation_ptr(ptr: *const QuotationData) -> Self

Create a NaN-boxed quotation pointer

Source

pub fn from_closure_ptr(ptr: *const ClosureData) -> Self

Create a NaN-boxed closure pointer

Source

pub fn from_channel_ptr(ptr: *const Arc<ChannelData>) -> Self

Create a NaN-boxed channel pointer

Source

pub fn from_weave_ctx_ptr(ptr: *const WeaveCtxData) -> Self

Create a NaN-boxed weave context pointer

Source

pub fn as_float(self) -> f64

Extract a float value

§Panics

Panics in debug mode if this is not a float.

Source

pub fn as_int(self) -> i64

Extract an integer value

§Panics

Panics in debug mode if this is not an integer.

Source

pub fn as_bool(self) -> bool

Extract a boolean value

§Panics

Panics in debug mode if this is not a boolean.

Source

pub unsafe fn as_string_ptr(self) -> *const SeqString

Extract a string pointer

§Safety

The caller must ensure this is a String value.

Source

pub unsafe fn as_symbol_ptr(self) -> *const SeqString

Extract a symbol pointer

§Safety

The caller must ensure this is a Symbol value.

Source

pub unsafe fn as_variant_ptr(self) -> *const Arc<VariantData>

Extract a variant pointer

§Safety

The caller must ensure this is a Variant value.

Source

pub unsafe fn as_map_ptr(self) -> *const Box<HashMap<MapKey, Value>>

Extract a map pointer

§Safety

The caller must ensure this is a Map value.

Source

pub unsafe fn as_quotation_ptr(self) -> *const QuotationData

Extract a quotation pointer

§Safety

The caller must ensure this is a Quotation value.

Source

pub unsafe fn as_closure_ptr(self) -> *const ClosureData

Extract a closure pointer

§Safety

The caller must ensure this is a Closure value.

Source

pub unsafe fn as_channel_ptr(self) -> *const Arc<ChannelData>

Extract a channel pointer

§Safety

The caller must ensure this is a Channel value.

Source

pub unsafe fn as_weave_ctx_ptr(self) -> *const WeaveCtxData

Extract a weave context pointer

§Safety

The caller must ensure this is a WeaveCtx value.

Source

pub fn to_bits(self) -> u64

Get the raw 64-bit representation

Source

pub unsafe fn from_bits(bits: u64) -> Self

Create from raw 64-bit representation

§Safety

The caller must ensure the bits represent a valid NanBoxedValue.

Source§

impl NanBoxedValue

Source

pub fn from_value(value: &Value) -> Self

Convert a Value to a NanBoxedValue

This clones heap-allocated data and stores pointers in the NaN-boxed format. The caller is responsible for ensuring the returned NanBoxedValue is properly dropped (via drop_nanboxed) to avoid memory leaks.

§Panics

Panics if an integer value is outside the 47-bit range.

Source

pub unsafe fn to_value(self) -> Value

Convert a NanBoxedValue back to a Value

This reconstructs the Value from the NaN-boxed representation. For heap-allocated types, this takes ownership of the underlying memory.

§Safety

The NanBoxedValue must have been created by from_value and not yet converted back or dropped. Each NanBoxedValue should only be converted to Value once.

Source

pub fn clone_nanboxed(&self) -> Self

Clone a NanBoxedValue, properly cloning any heap-allocated data

For pointer types, this creates new heap allocations.

Source

pub unsafe fn drop_nanboxed(self)

Drop a NanBoxedValue, freeing any heap-allocated data

This must be called for NanBoxedValues that hold pointer types to avoid memory leaks.

§Safety

The NanBoxedValue must have been created by from_value or clone_nanboxed and not yet dropped or converted to Value.

Trait Implementations§

Source§

impl Clone for NanBoxedValue

Source§

fn clone(&self) -> NanBoxedValue

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NanBoxedValue

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for NanBoxedValue

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Copy for NanBoxedValue

Source§

impl Send for NanBoxedValue

Source§

impl Sync for NanBoxedValue

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.