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,
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
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.
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.
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
impl Value
pub fn as_int(&self) -> i64
pub fn as_float(&self) -> f64
pub fn as_bool(&self) -> bool
pub fn as_str(&self) -> &str
Sourcepub fn to_json(&self) -> Value
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 { fn_id, .. }→"<closure fn_N>"Bytes→{"$bytes": "deadbeef"}(lowercase hex). Round-trips throughfrom_json. Bare hex strings decode asStr, so the marker is required to disambiguate bytes from a string that happens to look like hex.Mapwith all-Strkeys → 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).
Sourcepub fn from_json(v: &Value) -> Value
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 toValue::Record, matching the malformed-$variantfallback)- 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.