#[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
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
format: PathFormatListBool(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
impl ExprValue
Sourcepub fn make_list_checked(
ctx: &mut dyn EvalContext,
elements: Vec<ExprValue>,
hint_type: ExprType,
) -> Result<Self, ExpressionError>
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.
Sourcepub fn make_list(
elements: Vec<ExprValue>,
hint_type: ExprType,
) -> Result<Self, ExpressionError>
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.
Sourcepub fn unresolved(constraint: ExprType) -> Self
pub fn unresolved(constraint: ExprType) -> Self
Create an unresolved value with a type constraint (for validation-time type checking).
Sourcepub fn is_unresolved(&self) -> bool
pub fn is_unresolved(&self) -> bool
Returns true if this is an Unresolved value.
Sourcepub fn new_path(value: impl Into<String>, format: PathFormat) -> Self
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 characterWindows:/→\(unless the value is a URI)Uri: no normalization
Sourcepub fn from_str_coerce(
s: &str,
target: &ExprType,
path_format: PathFormat,
) -> Result<Self, String>
pub fn from_str_coerce( s: &str, target: &ExprType, path_format: PathFormat, ) -> Result<Self, String>
Coerce a string value to the given type.
Sourcepub fn coerce(
self,
target: &ExprType,
path_format: PathFormat,
) -> Result<Self, String>
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:
- Match first — if the value’s type is already one of the union members, return it unchanged.
- Per-member coercion — otherwise try non-destructive
coercion to each scalar member (skipping
nulltype,list[T], and nested unions). Return the first successful coercion. - 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.
Sourcepub fn repr_python(&self) -> String
pub fn repr_python(&self) -> String
Python-style repr: ExprValue(42), ExprValue('hello'), ExprValue([1, 2], type='list[int]').
Sourcepub fn to_json_transport(&self) -> Value
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.
pub fn transport_value(&self) -> Value
Sourcepub fn from_json_transport(
json: &Value,
path_format: PathFormat,
) -> Result<Self, String>
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.
pub fn from_transport_value( value: &Value, target: &ExprType, path_format: PathFormat, ) -> Result<Self, String>
Sourcepub fn list_elements(&self) -> Option<Vec<ExprValue>>
pub fn list_elements(&self) -> Option<Vec<ExprValue>>
Collect all elements into a Vec. Prefer list_iter to avoid allocation.
Sourcepub fn list_iter(&self) -> Option<ListIter<'_>>
pub fn list_iter(&self) -> Option<ListIter<'_>>
Iterate over list elements without allocating a Vec. Returns None for non-list values.
Sourcepub fn list_get(&self, index: i64) -> Option<ExprValue>
pub fn list_get(&self, index: i64) -> Option<ExprValue>
Get a single element by index without allocating. Supports negative indexing (Python-style).
Sourcepub fn list_elem_type(&self) -> Option<ExprType>
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.
Sourcepub fn into_list(self) -> Option<(Vec<ExprValue>, ExprType)>
pub fn into_list(self) -> Option<(Vec<ExprValue>, ExprType)>
Destructure into (elements, elem_type) for migration compatibility.
Sourcepub fn as_str_repr(&self) -> Cow<'_, str>
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.
Sourcepub fn to_display_string(&self) -> String
pub fn to_display_string(&self) -> String
Human-readable string for format string interpolation and display.
Sourcepub fn memory_size(&self) -> usize
pub fn memory_size(&self) -> usize
Memory size: size_of::<ExprValue> (the enum itself) plus heap allocations.
Trait Implementations§
impl Eq for ExprValue
Auto Trait Implementations§
impl Freeze for ExprValue
impl RefUnwindSafe for ExprValue
impl Send for ExprValue
impl Sync for ExprValue
impl Unpin for ExprValue
impl UnsafeUnpin for ExprValue
impl UnwindSafe for ExprValue
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,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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