Skip to main content

Value

Struct Value 

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

The core Value type for all Sema data. NaN-boxed: stored as 8 bytes. Floats stored directly, everything else encoded in quiet-NaN payload space.

Implementations§

Source§

impl Value

Source

pub const NIL: Value

Source

pub const TRUE: Value

Source

pub const FALSE: Value

Source

pub fn nil() -> Value

Source

pub fn bool(b: bool) -> Value

Source

pub fn int(n: i64) -> Value

Source

pub fn float(f: f64) -> Value

Source

pub fn char(c: char) -> Value

Source

pub fn symbol_from_spur(spur: Spur) -> Value

Source

pub fn symbol(s: &str) -> Value

Source

pub fn keyword_from_spur(spur: Spur) -> Value

Source

pub fn keyword(s: &str) -> Value

Source

pub fn from_bigint(n: BigInt) -> Value

Construct an integer of any magnitude, normalizing to the tightest representation: values in i64 range become a fixnum/int-big, larger values are heap-boxed under TAG_BIGINT.

Source

pub fn rational(r: BigRational) -> Value

Construct an exact rational, normalizing integer-valued rationals (e.g. 6/3) down to the tightest integer representation.

Source

pub fn complex(re: SemaNumber, im: SemaNumber) -> Value

Construct a complex number from its real/imaginary tower components, normalizing an exact-zero imaginary part down to the real part alone.

Source

pub fn string(s: &str) -> Value

Source

pub fn string_owned(s: String) -> Value

Construct a string value from an already-owned String without the extra copy Value::string(&s) would make. Prefer this whenever the caller has just built the String and won’t use it again.

Source

pub fn string_from_rc(rc: Rc<String>) -> Value

Source

pub fn list(v: Vec<Value>) -> Value

Source

pub fn list_from_rc(rc: Rc<Vec<Value>>) -> Value

Source

pub fn vector(v: Vec<Value>) -> Value

Source

pub fn vector_from_rc(rc: Rc<Vec<Value>>) -> Value

Source

pub fn map(m: BTreeMap<Value, Value>) -> Value

Source

pub fn map_from_rc(rc: Rc<BTreeMap<Value, Value>>) -> Value

Source

pub fn hashmap(entries: Vec<(Value, Value)>) -> Value

Source

pub fn hashmap_from_rc(rc: Rc<HashMap<Value, Value>>) -> Value

Source

pub fn lambda(l: Lambda) -> Value

Source

pub fn lambda_from_rc(rc: Rc<Lambda>) -> Value

Source

pub fn macro_val(m: Macro) -> Value

Source

pub fn macro_from_rc(rc: Rc<Macro>) -> Value

Source

pub fn native_fn(f: NativeFn) -> Value

Source

pub fn native_fn_from_rc(rc: Rc<NativeFn>) -> Value

Source

pub fn prompt(p: Prompt) -> Value

Source

pub fn prompt_from_rc(rc: Rc<Prompt>) -> Value

Source

pub fn message(m: Message) -> Value

Source

pub fn message_from_rc(rc: Rc<Message>) -> Value

Source

pub fn conversation(c: Conversation) -> Value

Source

pub fn conversation_from_rc(rc: Rc<Conversation>) -> Value

Source

pub fn tool_def(t: ToolDefinition) -> Value

Source

pub fn tool_def_from_rc(rc: Rc<ToolDefinition>) -> Value

Source

pub fn agent(a: Agent) -> Value

Source

pub fn agent_from_rc(rc: Rc<Agent>) -> Value

Source

pub fn thunk(t: Thunk) -> Value

Source

pub fn thunk_from_rc(rc: Rc<Thunk>) -> Value

Source

pub fn record(r: Record) -> Value

Source

pub fn record_from_rc(rc: Rc<Record>) -> Value

Source

pub fn bytevector(bytes: Vec<u8>) -> Value

Source

pub fn bytevector_from_rc(rc: Rc<Vec<u8>>) -> Value

Source

pub fn f64_array(data: Vec<f64>) -> Value

Source

pub fn f64_array_from_rc(rc: Rc<Vec<f64>>) -> Value

Source

pub fn i64_array(data: Vec<i64>) -> Value

Source

pub fn i64_array_from_rc(rc: Rc<Vec<i64>>) -> Value

Source

pub fn multimethod(m: MultiMethod) -> Value

Source

pub fn multimethod_from_rc(rc: Rc<MultiMethod>) -> Value

Source

pub fn stream(s: impl SemaStream + 'static) -> Value

Source

pub fn stream_from_rc(rc: Rc<StreamBox>) -> Value

Source

pub fn async_promise(promise: AsyncPromise) -> Value

Source

pub fn async_promise_id(id: PromiseId) -> Value

Build a promise Value from a runtime PromiseId. The registry owns the promise’s state; this is just the language-facing handle to it.

Source

pub fn async_promise_from_rc(rc: Rc<AsyncPromise>) -> Value

Rebuild a promise handle Value from an existing Rc WITHOUT re-registering a GC candidate — used by the collector to upgrade a candidate Weak into a snapshot handle for the duration of a pass.

Source

pub fn channel(ch: Channel) -> Value

Source

pub fn channel_id(id: ChannelId) -> Value

Build a channel Value from a runtime ChannelId. The registry owns the channel’s buffer/state; this is just the language-facing handle to it.

Source

pub fn channel_from_rc(rc: Rc<Channel>) -> Value

Rebuild a channel handle Value from an existing Rc WITHOUT re-registering a GC candidate — used by the collector to upgrade a candidate Weak into a snapshot handle for the duration of a pass.

Source

pub fn mutable_array(items: Vec<Value>) -> Value

Source

pub fn mutable_array_from_rc(rc: Rc<MutableArray>) -> Value

Source

pub fn mutable_cell(value: Value) -> Value

Source

pub fn mutable_cell_from_rc(rc: Rc<MutableCell>) -> Value

Source§

impl Value

Source

pub fn raw_bits(&self) -> u64

Get the raw bits (for debugging/testing).

Source

pub unsafe fn from_raw_bits(bits: u64) -> Value

Construct a Value from raw NaN-boxed bits.

§Safety

Caller must ensure bits represents a valid NaN-boxed value. For immediate types (nil, bool, int, symbol, keyword, char), this is always safe. For heap-pointer types, the encoded pointer must be valid and have its Rc ownership accounted for (i.e., the caller must ensure the refcount is correct).

Source

pub fn raw_tag(&self) -> Option<u64>

Get the NaN-boxing tag of a boxed value (0-63). Returns None for non-boxed values (floats).

Source

pub fn as_native_fn_ref(&self) -> Option<&NativeFn>

Borrow the underlying NativeFn without bumping the Rc refcount. SAFETY: The returned reference is valid as long as this Value is alive.

Source

pub fn is_float(&self) -> bool

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

Source

pub fn view(&self) -> ValueView

Pattern-match friendly view of this value. For heap types, this bumps the Rc refcount.

Source

pub fn view_ref(&self) -> ValueViewRef<'_>

Borrowing view — like view() but returns references instead of bumping Rc refcounts. Use this in hot paths like PartialEq, Hash, Ord, and Display.

Source

pub fn type_name(&self) -> &'static str

Source

pub fn is_nil(&self) -> bool

Source

pub fn is_truthy(&self) -> bool

Source

pub fn is_falsy(&self) -> bool

Source

pub fn is_bool(&self) -> bool

Source

pub fn is_int(&self) -> bool

Source

pub fn is_bigint(&self) -> bool

Source

pub fn is_rational(&self) -> bool

Source

pub fn is_complex(&self) -> bool

Source

pub fn is_symbol(&self) -> bool

Source

pub fn is_keyword(&self) -> bool

Source

pub fn is_string(&self) -> bool

Source

pub fn is_list(&self) -> bool

Source

pub fn is_pair(&self) -> bool

Source

pub fn is_vector(&self) -> bool

Source

pub fn is_map(&self) -> bool

Source

pub fn is_lambda(&self) -> bool

Source

pub fn is_native_fn(&self) -> bool

Source

pub fn is_thunk(&self) -> bool

Source

pub fn is_async_promise(&self) -> bool

Source

pub fn is_channel(&self) -> bool

Source

pub fn is_record(&self) -> bool

Source

pub fn as_int(&self) -> Option<i64>

Source

pub fn as_bigint(&self) -> Option<BigInt>

Lift any integer Value (fixnum, int-big, or bignum) to BigInt. None for non-integers.

Source

pub fn as_rational(&self) -> Option<BigRational>

Lift any exact Value (fixnum, bignum, or rational) to BigRational. None for non-exact-numeric Values (including floats).

Source

pub fn as_number(&self) -> Option<SemaNumber>

Lift any numeric Value into the tower type for arithmetic. None for non-numbers.

Source

pub fn from_number(n: SemaNumber) -> Value

Lower a tower number to the tightest Value.

Source

pub fn as_complex(&self) -> Option<SemaComplex>

Lift a complex Value to the tower’s Complex component pair. None for non-complex Values.

Source

pub fn as_index(&self, name: &str) -> Result<usize, SemaError>

Convert a user-supplied integer to a usize index/count, rejecting non-integers and negative values. Centralizes the negativity guard that list/take, list/drop, string/repeat (and the Pattern-A audit sites) all need — a bare as usize would wrap a negative i64 to a huge value and trigger an OOM allocation or out-of-bounds panic.

Source

pub fn as_float(&self) -> Option<f64>

Source

pub fn as_bool(&self) -> Option<bool>

Source

pub fn as_str(&self) -> Option<&str>

Source

pub fn as_string_rc(&self) -> Option<Rc<String>>

Source

pub fn as_symbol(&self) -> Option<String>

Source

pub fn as_symbol_spur(&self) -> Option<Spur>

Source

pub fn as_keyword(&self) -> Option<String>

Source

pub fn as_keyword_spur(&self) -> Option<Spur>

Source

pub fn as_char(&self) -> Option<char>

Source

pub fn as_list(&self) -> Option<&[Value]>

Source

pub fn as_list_rc(&self) -> Option<Rc<Vec<Value>>>

Source

pub fn as_seq(&self) -> Option<&[Value]>

Returns the contents as a slice if this is a list OR a vector.

Source

pub fn as_vector(&self) -> Option<&[Value]>

Source

pub fn as_vector_rc(&self) -> Option<Rc<Vec<Value>>>

Source

pub fn as_map_rc(&self) -> Option<Rc<BTreeMap<Value, Value>>>

Source

pub fn as_hashmap_rc(&self) -> Option<Rc<HashMap<Value, Value>>>

Source

pub fn as_hashmap_ref(&self) -> Option<&HashMap<Value, Value>>

Borrow the underlying HashMap without bumping the Rc refcount.

Source

pub fn as_map_ref(&self) -> Option<&BTreeMap<Value, Value>>

Borrow the underlying BTreeMap without bumping the Rc refcount.

Source

pub fn with_hashmap_mut_if_unique<R>( &self, f: impl FnOnce(&mut HashMap<Value, Value>) -> R, ) -> Option<R>

If this is a hashmap with refcount==1, mutate it in place. Returns None if not a hashmap or if shared (refcount > 1). SAFETY: relies on no other references to the inner data existing.

Source

pub fn with_map_mut_if_unique<R>( &self, f: impl FnOnce(&mut BTreeMap<Value, Value>) -> R, ) -> Option<R>

If this is a map (BTreeMap) with refcount==1, mutate it in place. Returns None if not a map or if shared (refcount > 1).

Source

pub fn into_hashmap_rc(self) -> Result<Rc<HashMap<Value, Value>>, Value>

Consume this Value and extract the inner Rc without a refcount bump. Returns Err(self) if not a hashmap.

Source

pub fn into_map_rc(self) -> Result<Rc<BTreeMap<Value, Value>>, Value>

Consume this Value and extract the inner Rc without a refcount bump. Returns Err(self) if not a map.

Source

pub fn as_lambda_rc(&self) -> Option<Rc<Lambda>>

Source

pub fn as_macro_rc(&self) -> Option<Rc<Macro>>

Source

pub fn as_native_fn_rc(&self) -> Option<Rc<NativeFn>>

Source

pub fn as_thunk_rc(&self) -> Option<Rc<Thunk>>

Source

pub fn as_record(&self) -> Option<&Record>

Source

pub fn as_record_rc(&self) -> Option<Rc<Record>>

Source

pub fn as_bytevector(&self) -> Option<&[u8]>

Source

pub fn as_bytevector_rc(&self) -> Option<Rc<Vec<u8>>>

Source

pub fn as_f64_array(&self) -> Option<&[f64]>

Source

pub fn as_f64_array_rc(&self) -> Option<Rc<Vec<f64>>>

Source

pub fn as_i64_array(&self) -> Option<&[i64]>

Source

pub fn as_i64_array_rc(&self) -> Option<Rc<Vec<i64>>>

Source

pub fn as_stream(&self) -> Option<&StreamBox>

Source

pub fn as_stream_rc(&self) -> Option<Rc<StreamBox>>

Source

pub fn as_prompt_rc(&self) -> Option<Rc<Prompt>>

Source

pub fn as_message_rc(&self) -> Option<Rc<Message>>

Source

pub fn as_conversation_rc(&self) -> Option<Rc<Conversation>>

Source

pub fn as_tool_def_rc(&self) -> Option<Rc<ToolDefinition>>

Source

pub fn as_agent_rc(&self) -> Option<Rc<Agent>>

Source

pub fn as_multimethod_rc(&self) -> Option<Rc<MultiMethod>>

Source

pub fn as_mutable_array(&self) -> Option<&MutableArray>

Source

pub fn as_mutable_array_rc(&self) -> Option<Rc<MutableArray>>

Source

pub fn as_mutable_cell(&self) -> Option<&MutableCell>

Source

pub fn as_mutable_cell_rc(&self) -> Option<Rc<MutableCell>>

Source

pub fn is_mutable_container(&self) -> bool

True for interior-mutable containers (mutable arrays and cells), whose contents can change after a map insertion. Map constructors reject these as keys — a mutated key would silently corrupt lookup order.

Source

pub fn contains_mutable_container(&self) -> bool

True if this value is, or transitively contains, an interior-mutable container. Map keys must be deeply immutable: a vector wrapping a mutable array still mutates underneath the map, corrupting lookup order just as a bare mutable key would (Ord recurses into container elements). Iterative worklist — no visited set or depth cap needed because the walk never descends into a mutable container (it returns true on sight) and cycles are only constructible through one.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Value

Source§

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

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

impl Display for Value

Source§

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

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

impl Drop for Value

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Eq for Value

Source§

impl Hash for Value

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Value

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for Value

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for Value

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations§

§

impl Freeze for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnsafeUnpin for Value

§

impl UnwindSafe for Value

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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.