Skip to main content

Value

Enum Value 

Source
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

Source

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).

Source

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).

Source

pub fn option_some(value: Value) -> Self

Build the standard Some(value) tagged value.

Source

pub fn option_none() -> Self

Build the standard None tagged value.

Source

pub fn result_ok(value: Value) -> Self

Build the standard Ok(value) tagged value.

Source

pub fn result_err(error: Value) -> Self

Build the standard Err(error) tagged value.

Source

pub fn is_option_none(&self) -> bool

True for the standard None tagged value.

Source

pub fn option_some_value(&self) -> Option<&Value>

Return the payload of a standard Option.Some { value } tagged value.

Source

pub fn dict<K, I>(map: I) -> Self
where K: Into<SmolStr>, I: IntoIterator<Item = (K, Value)>,

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.

Source

pub fn branded_dict<K, I>(map: I, brand: Option<String>) -> Self
where K: Into<SmolStr>, I: IntoIterator<Item = (K, Value)>,

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.

Source

pub fn variant_dict<K, I>(map: I, variant: String, enum_name: String) -> Self
where K: Into<SmolStr>, I: IntoIterator<Item = (K, Value)>,

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.

Source

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.

Source

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.

Source

pub fn is_truthy(&self) -> bool

Source

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

Source

pub fn deep_merge(&mut self, patch: &Value)

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<'de> Deserialize<'de> for Value

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. 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 PartialEq for Value

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.
Source§

impl Serialize for Value

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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<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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
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> 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> 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 = 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.