pub enum Value {
Bool(bool),
Int(i64),
Float(OrderedFloat<f64>),
String(SmolStr),
List(Arc<Vec<Value>>),
Tuple(Arc<Vec<Value>>),
Dict(Arc<ValueDict>),
Closure(Box<ClosureData>),
Schema(Arc<SchemaData>),
EnumSchema(Arc<EnumSchemaData>),
Type(Box<TypeNode>),
Wildcard,
}Expand description
Aggregate value type produced by the evaluator.
List, Tuple, and Dict payloads are reference-counted: cloning a
Value::List, Value::Tuple, or Value::Dict only bumps an Arc and
does not copy the underlying
collection. Mutations go through Arc::make_mut (see Value::list_mut
and Value::dict_mut), which clones the inner value lazily on first
write — so existing aliases keep their snapshot semantics. This matters
because the evaluator caches resolved paths and module results in shared
path_cache/module_cache maps; without Arc-sharing every cache hit
would deep-clone the cached structure.
The “heavy” variants (Closure, Schema, EnumSchema) live behind
pointers so the enum stays narrow: the comprehension hot loop stores
Values in per-iteration scope HashMaps, and the bucket size scales
with the enum width. Schema / EnumSchema use Arc (P2-5) — the
check_type path clones the schema value out of the type table per
typed-field validation, and a deep field-map clone there was a
measurable cost; refcount-clone collapses it to a single atomic bump
while keeping immutable-snapshot semantics.
Variants§
Bool(bool)
Int(i64)
Float(OrderedFloat<f64>)
String(SmolStr)
Short-string-optimized: ≤ 22 byte payloads inline in the value
slot (no heap alloc), longer payloads ride a refcounted
Arc<str> so clones stay O(1). See SmolStr.
List(Arc<Vec<Value>>)
Tuple(Arc<Vec<Value>>)
Dict(Arc<ValueDict>)
Closure(Box<ClosureData>)
A unified closure (can be used as a function or a decorator).
Payload is boxed; see ClosureData.
Schema(Arc<SchemaData>)
A user-defined type schema. Payload is refcounted; see SchemaData.
EnumSchema(Arc<EnumSchemaData>)
A tagged-enum (sum-type) schema: variants by name, each with its
own field set. Built from #enum Name { Var1 { ... }, ... }
declarations. Construction with Name.Var1 { ... } is
dispatched via this value.
Payload is refcounted; see EnumSchemaData.
Type(Box<TypeNode>)
A single type description. The payload (TypeNode) carries a
TokenRange plus a Vec<TypeNode> of generics that together push
the inline size past 100 bytes; boxing keeps the enum compact
(matching the rationale for ClosureData et al.).
Wildcard
A wildcard predicate (*)
Implementations§
Source§impl Value
impl Value
Sourcepub fn list(items: Vec<Value>) -> Self
pub fn list(items: Vec<Value>) -> Self
Build a Value::List from a Vec, taking ownership and wrapping it
in Arc so subsequent clones are O(1).
Sourcepub fn tuple(items: Vec<Value>) -> Self
pub fn tuple(items: Vec<Value>) -> Self
Build a Value::Tuple from a Vec, taking ownership and wrapping it
in Arc so subsequent clones are O(1).
Sourcepub fn option_some(value: Value) -> Self
pub fn option_some(value: Value) -> Self
Build the standard Some(value) tagged value.
Sourcepub fn option_none() -> Self
pub fn option_none() -> Self
Build the standard None tagged value.
Sourcepub fn result_err(error: Value) -> Self
pub fn result_err(error: Value) -> Self
Build the standard Err(error) tagged value.
Sourcepub fn is_option_none(&self) -> bool
pub fn is_option_none(&self) -> bool
True for the standard None tagged value.
Sourcepub fn option_some_value(&self) -> Option<&Value>
pub fn option_some_value(&self) -> Option<&Value>
Return the payload of a standard Option.Some { value } tagged value.
Sourcepub fn dict<K, I>(map: I) -> Self
pub fn dict<K, I>(map: I) -> Self
Build a Value::Dict from any iterable of key/value pairs. The
generic key accepts either a SmolStr (zero-cost) or a String
(consumed and short-string-optimised via SmolStr::from). Use
Value::branded_dict when the dict carries a nominal-type brand.
Sourcepub fn branded_dict<K, I>(map: I, brand: Option<String>) -> Self
pub fn branded_dict<K, I>(map: I, brand: Option<String>) -> Self
Build a Value::Dict with an explicit brand (the typed-dict tag set
after a successful User x: { ... } validation, etc.). See
Value::dict for the key-type contract.
Sourcepub fn variant_dict<K, I>(map: I, variant: String, enum_name: String) -> Self
pub fn variant_dict<K, I>(map: I, variant: String, enum_name: String) -> Self
Build a Value::Dict representing a tagged-enum variant: carries a
brand (the variant name) plus variant_of (the parent enum name).
The JSON projector uses variant_of to externally tag the output.
See Value::dict for the key-type contract.
Sourcepub fn list_mut(&mut self) -> Option<&mut Vec<Value>>
pub fn list_mut(&mut self) -> Option<&mut Vec<Value>>
In-place mutable handle to a Value::List’s inner Vec. Clones the
inner allocation only if the Arc is shared with another holder.
Returns None for non-list values.
Sourcepub fn dict_mut(&mut self) -> Option<&mut ValueDict>
pub fn dict_mut(&mut self) -> Option<&mut ValueDict>
In-place mutable handle to a Value::Dict’s inner ValueDict.
CoW semantics — see Value::list_mut.
pub fn is_truthy(&self) -> bool
pub fn type_name(&self) -> &'static str
pub fn deep_merge(&mut self, patch: &Value)
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Value
impl<'de> Deserialize<'de> for Value
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
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> 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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more