Skip to main content

Value

Enum Value 

Source
pub enum Value {
Show 15 variants Int(i64), Float(f64), Bool(bool), Str(String), Bytes(Vec<u8>), Unit, List(Vec<Value>), Tuple(Vec<Value>), Record(IndexMap<String, Value>), Variant { name: String, args: Vec<Value>, }, Closure { fn_id: u32, body_hash: BodyHash, captures: Vec<Value>, }, F64Array { rows: u32, cols: u32, data: Vec<f64>, }, Map(BTreeMap<MapKey, Value>), Set(BTreeSet<MapKey>), Deque(VecDeque<Value>),
}

Variants§

§

Int(i64)

§

Float(f64)

§

Bool(bool)

§

Str(String)

§

Bytes(Vec<u8>)

§

Unit

§

List(Vec<Value>)

§

Tuple(Vec<Value>)

§

Record(IndexMap<String, Value>)

§

Variant

Fields

§name: String
§args: Vec<Value>
§

Closure

First-class function value (a lambda + its captured locals). The function’s first captures.len() params bind to captures; the remaining params are supplied at call time.

fn_id is a dense compile-time index into Program::functions for fast dispatch; body_hash is the canonical identity — two closures with identical bytecode bodies compare equal even when their fn_ids differ (which they will, when the source has the same closure literal at two locations). See PartialEq below and #222 for the rationale.

Fields

§fn_id: u32
§body_hash: BodyHash
§captures: Vec<Value>
§

F64Array

Dense row-major f64 matrix. A “fast lane” representation that avoids the per-element Value::Float boxing of Value::List. Used by Core’s native tensor ops (matmul, dot, …) so end-to-end matmul perf hits the §13.7 #1 100ms target without paying for 2M Value boxings at the call boundary.

Fields

§rows: u32
§cols: u32
§data: Vec<f64>
§

Map(BTreeMap<MapKey, Value>)

Persistent map keyed by MapKey (Str or Int). Insertion- independent equality (sorted by BTreeMap’s Ord), so two maps built from the same pairs in different orders compare equal. Restricting keys to two primitive variants keeps Eq + Hash requirements off Value itself, which has closures and floats and can’t be hashed soundly.

§

Set(BTreeSet<MapKey>)

Persistent set with the same key-type discipline as Map.

§

Deque(VecDeque<Value>)

Double-ended queue. O(1) push/pop on both ends; otherwise behaves like List for iteration / equality / JSON shape. Lex’s type system tracks Deque[T] separately from List[T] so users explicitly opt in to deque semantics; the runtime uses this dedicated variant rather than backing a deque on top of Value::List (which would make push_front O(n)).

Implementations§

Source§

impl Value

Source

pub fn as_int(&self) -> i64

Source

pub fn as_float(&self) -> f64

Source

pub fn as_bool(&self) -> bool

Source

pub fn as_str(&self) -> &str

Source

pub fn to_json(&self) -> Value

Render this Value as a serde_json::Value for emission to CLI output, the agent API, conformance harness reports, etc. Canonical mapping shared across crates; previously every boundary had its own copy.

Encoding:

  • Variant { name, args }{"$variant": name, "args": [...]}
  • F64Array { ... }{"$f64_array": true, rows, cols, data}
  • Closure { body_hash, .. }"<closure HEX8>" (first 8 hex chars of the body hash; equivalent closures across source locations render identically — see #222)
  • Bytes{"$bytes": "deadbeef"} (lowercase hex). Round-trips through from_json. Bare hex strings decode as Str, so the marker is required to disambiguate bytes from a string that happens to look like hex.
  • Map with all-Str keys → JSON object; otherwise array of [key, value] pairs (Int keys can’t be JSON-object keys)
  • Set → JSON array of elements
  • other variants → their natural JSON shape

Note: this form is not round-trippable for traces (see lex-trace’s recorder, which uses a richer marker form).

Source

pub fn from_json(v: &Value) -> Value

Decode a serde_json::Value into a Value. The inverse of to_json for the shapes Lex round-trips:

  • {"$variant": "Name", "args": [...]}Value::Variant
  • {"$bytes": "deadbeef"}Value::Bytes (lowercase hex; an odd-length string or non-hex character falls through to Value::Record, matching the malformed-$variant fallback)
  • JSON object → Value::Record
  • JSON array → Value::List
  • JSON null → Value::Unit
  • JSON string / bool / number → the corresponding scalar

Map, Set, F64Array, and Closure don’t round-trip — they decode as their natural JSON shape (Object / Array / Object / Str respectively), since the CLI / HTTP / VM callers building Values from JSON don’t have those shapes in their input vocabulary.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

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 PartialEq for Value

Manual PartialEq for Value (#222). Mirrors the auto-derived implementation for every variant except Closure, which compares on (body_hash, captures) only — fn_id is a dense compile-time index that is not stable across source-location-equivalent closure literals, and including it would defeat the canonicality property the body_hash field exists to provide.

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

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<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> Same for T

Source§

type Output = T

Should always be Self
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.