Skip to main content

ExprValue

Enum ExprValue 

Source
#[non_exhaustive]
pub enum ExprValue {
Show 14 variants Null, Bool(bool), Int(i64), Float(Float64), String(String),
#[non_exhaustive]
Path { value: String, format: PathFormat, }, ListBool(Vec<bool>), ListInt(Vec<i64>), ListFloat(Vec<Float64>), ListString(Vec<String>, usize), ListPath(Vec<String>, PathFormat, usize), ListList(Vec<ExprValue>, ExprType, usize), RangeExpr(RangeExpr), Unresolved(ExprType),
}
Expand description

A typed value during expression evaluation.

#[non_exhaustive] because future revisions or extensions may add new primitive types (e.g., Duration, Url, Decimal). Adding a variant must not be a breaking change for downstream crates that match on this enum. The Path variant has its own #[non_exhaustive] attribute, which serves a separate purpose (preventing direct struct-literal construction so that ExprValue::new_path can enforce the separator-normalization invariant).

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Null

§

Bool(bool)

§

Int(i64)

§

Float(Float64)

§

String(String)

§

#[non_exhaustive]
Path

A PATH value — a string path together with its format.

#[non_exhaustive] prevents direct construction outside this crate; downstream callers must use ExprValue::new_path, which enforces the separator-normalization invariant (\/ per PathFormat, and no normalization for URI paths). The fields remain visible for pattern matching (using .. is required from outside the crate).

Fields

This variant is marked as non-exhaustive
Non-exhaustive enum variants could have additional fields added in future. Therefore, non-exhaustive enum variants cannot be constructed in external crates and cannot be matched against.
§value: String
§format: PathFormat
§

ListBool(Vec<bool>)

§

ListInt(Vec<i64>)

§

ListFloat(Vec<Float64>)

§

ListString(Vec<String>, usize)

§

ListPath(Vec<String>, PathFormat, usize)

§

ListList(Vec<ExprValue>, ExprType, usize)

§

RangeExpr(RangeExpr)

§

Unresolved(ExprType)

Implementations§

Source§

impl ExprValue

Source

pub fn make_list_checked( ctx: &mut dyn EvalContext, elements: Vec<ExprValue>, hint_type: ExprType, ) -> Result<Self, ExpressionError>

Memory-checked variant of make_list.

Pre-checks the evaluator’s memory budget against an upper-bound estimate of the list’s heap footprint before any allocation occurs. This is the defense-in-depth path: call sites that have an EvalContext available should prefer this over make_list so that a memory-bounded evaluator fails cleanly on oversized intermediate lists — even from code paths that did not charge ops proportionally to the list size.

Type promotion and nesting validation are otherwise identical to make_list; this function forwards to it after the memory check passes.

Source

pub fn make_list( elements: Vec<ExprValue>, hint_type: ExprType, ) -> Result<Self, ExpressionError>

Construct a typed list from heterogeneous elements.

Applies type promotion rules: int+float→float, path+string→string. Uses hint_type for empty lists to determine the element type. Returns an error if any element is a ListList, which would create 3+ nesting levels.

When called from an evaluator or function implementation that has an EvalContext, prefer make_list_checked so that an oversized intermediate list fails the evaluator’s memory limit before the allocation happens.

Source

pub fn unresolved(constraint: ExprType) -> Self

Create an unresolved value with a type constraint (for validation-time type checking).

Source

pub fn is_unresolved(&self) -> bool

Returns true if this is an Unresolved value.

Source

pub fn new_path(value: impl Into<String>, format: PathFormat) -> Self

Create a PATH value with separators normalized to the given format.

This is the only public constructor for ExprValue::Path; the variant itself is #[non_exhaustive] so downstream crates cannot bypass the separator-normalization invariant by constructing the struct directly.

  • Posix: no normalization — backslash is a valid filename character
  • Windows: /\ (unless the value is a URI)
  • Uri: no normalization
Source

pub fn from_str_coerce( s: &str, target: &ExprType, path_format: PathFormat, ) -> Result<Self, String>

Coerce a string value to the given type.

Source

pub fn coerce( self, target: &ExprType, path_format: PathFormat, ) -> Result<Self, String>

Coerce a value to the given type.

Coercion is non-destructive: only conversions that don’t lose information are attempted (int → float, int → string, etc).

For union targets, the rules are:

  1. Match first — if the value’s type is already one of the union members, return it unchanged.
  2. Per-member coercion — otherwise try non-destructive coercion to each scalar member (skipping nulltype, list[T], and nested unions). Return the first successful coercion.
  3. Error — if neither step yields a result.

This mirrors the behavior of the pure-Python reference implementation’s evaluate.try_coerce_nondestructive loop and satisfies RFC 0005 §“Implicit Type Coercion”: int | string accepts an int value as-is rather than rejecting it.

Source

pub fn repr_python(&self) -> String

Python-style repr: ExprValue(42), ExprValue('hello'), ExprValue([1, 2], type='list[int]').

Source

pub fn to_json_transport(&self) -> Value

Serialize to JSON transport format: {"type": "int", "value": "42"}. Lists serialize value as nested JSON arrays of strings. The caller adds the "name" field.

Source

pub fn transport_value(&self) -> Value

Source

pub fn from_json_transport( json: &Value, path_format: PathFormat, ) -> Result<Self, String>

Deserialize from JSON transport format. json must have "type" and "value" fields.

Source

pub fn from_transport_value( value: &Value, target: &ExprType, path_format: PathFormat, ) -> Result<Self, String>

Source

pub fn is_list(&self) -> bool

Returns true if this value is a list variant.

Source

pub fn list_len(&self) -> Option<usize>

Number of elements if this is a list, None otherwise.

Source

pub fn list_elements(&self) -> Option<Vec<ExprValue>>

Collect all elements into a Vec. Prefer list_iter to avoid allocation.

Source

pub fn list_iter(&self) -> Option<ListIter<'_>>

Iterate over list elements without allocating a Vec. Returns None for non-list values.

Source

pub fn list_get(&self, index: i64) -> Option<ExprValue>

Get a single element by index without allocating. Supports negative indexing (Python-style).

Source

pub fn list_elem_type(&self) -> Option<ExprType>

Element type of a list, or None for non-list values.

Returns the element type based on the list variant, even for empty lists. For example, an empty ListString returns STRING, not NULLTYPE. This ensures that operations on empty typed lists (e.g. sorted([]) where [] was originally list[string]) preserve the element type through round-trips via into_list + make_list.

Source

pub fn into_list(self) -> Option<(Vec<ExprValue>, ExprType)>

Destructure into (elements, elem_type) for migration compatibility.

Source

pub fn expr_type(&self) -> ExprType

The ExprType of this value.

Source

pub fn as_str_repr(&self) -> Cow<'_, str>

Get a string representation for use in path manipulation and constraint checking. Returns a Cow to avoid allocation when the value is already a string.

Source

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

Short type name for error messages.

Source

pub fn to_display_string(&self) -> String

Human-readable string for format string interpolation and display.

Source

pub fn memory_size(&self) -> usize

Memory size: size_of::<ExprValue> (the enum itself) plus heap allocations.

Source

pub fn equals(&self, other: &ExprValue) -> bool

Value equality with cross-type support (Int↔Float, String↔Path).

Source

pub fn compare(&self, other: &ExprValue) -> Result<Ordering, ExpressionError>

Ordering comparison. Returns Err for incomparable types.

Trait Implementations§

Source§

impl Clone for ExprValue

Source§

fn clone(&self) -> ExprValue

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 ExprValue

Source§

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

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

impl From<&str> for ExprValue

Source§

fn from(v: &str) -> Self

Converts to this type from the input type.
Source§

impl From<ExprType> for ExprValue

Source§

fn from(t: ExprType) -> Self

Converts to this type from the input type.
Source§

impl From<RangeExpr> for ExprValue

Source§

fn from(v: RangeExpr) -> Self

Converts to this type from the input type.
Source§

impl From<String> for ExprValue

Source§

fn from(v: String) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for ExprValue

Source§

fn from(v: bool) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for ExprValue

Source§

fn from(v: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for ExprValue

Source§

fn from(v: i64) -> Self

Converts to this type from the input type.
Source§

impl Hash for ExprValue

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

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 ExprValue

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

impl Eq for ExprValue

Auto Trait Implementations§

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