pub enum Value {
Empty,
Errata(Errata),
Literal(Literal),
Array(Arc<Vec<Arc<Value>>>),
Collection(Arc<HashMap<Arc<str>, Arc<Expression>>>),
Branch(Arc<str>),
Closure(Arc<Closure>),
Eval(Eval),
Format(Format),
Instance(Instance),
Node(Node),
}Expand description
Unified runtime value used by AIMX evaluation.
Value represents evaluated data flowing through the engine: literals,
arrays, collections, closures, workflow/inference types, branches, and
Errata. Helper methods provide type inspection, conversions following
AIMX rules, and formatting.
Variants§
Empty
Errata(Errata)
Literal(Literal)
Array(Arc<Vec<Arc<Value>>>)
Collection(Arc<HashMap<Arc<str>, Arc<Expression>>>)
Branch(Arc<str>)
Closure(Arc<Closure>)
Eval(Eval)
Format(Format)
Instance(Instance)
Node(Node)
Implementations§
Source§impl Value
impl Value
pub fn convert(input: Arc<str>) -> Arc<Self>
pub fn empty() -> Arc<Self>
pub fn empty_str() -> Arc<str>
Sourcepub fn from_number(number: f64) -> Value
pub fn from_number(number: f64) -> Value
Convenience constructor for a numeric Value.
Sourcepub fn from_arc_str(text: Arc<str>) -> Self
pub fn from_arc_str(text: Arc<str>) -> Self
Convenience constructor for a text Value.
Sourcepub fn is_of_type(&self, typedef: &Typedef) -> bool
pub fn is_of_type(&self, typedef: &Typedef) -> bool
Return true if this value conforms to the given Typedef.
Sourcepub fn is_actual_type(&self, typedef: &Typedef) -> bool
pub fn is_actual_type(&self, typedef: &Typedef) -> bool
Return true if this value’s structure matches typedef, including nested arrays.
Sourcepub fn get_type(&self) -> Result<Typedef>
pub fn get_type(&self) -> Result<Typedef>
Get the type of this value.
§Returns
Returns a Result<Typedef> containing the type of this value,
or an error if this is an Empty value.
Sourcepub fn as_type(self: Arc<Value>, value: Arc<Value>) -> Result<Arc<Value>>
pub fn as_type(self: Arc<Value>, value: Arc<Value>) -> Result<Arc<Value>>
Convert this value to match the type of value (based on its literal variant).
Sourcepub fn to_type(self: Arc<Value>, typedef: &Typedef) -> Result<Arc<Value>>
pub fn to_type(self: Arc<Value>, typedef: &Typedef) -> Result<Arc<Value>>
Convert this value to a specific Typedef using AIMX promotion rules.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Check if this value is empty.
Returns true if this value is the Empty variant, false otherwise.
Sourcepub fn is_error(&self) -> bool
pub fn is_error(&self) -> bool
Check if this value contains an error.
Returns true if this value represents an error condition,
false otherwise.
Sourcepub fn is_literal(&self) -> bool
pub fn is_literal(&self) -> bool
Check if this value is a literal.
Returns true if this value is the Literal variant, false otherwise.
This includes all scalar types: booleans, numbers, text, dates, and tasks.
Sourcepub fn is_constant(&self) -> bool
pub fn is_constant(&self) -> bool
Check if this value is constant (immutable).
Returns true if this value represents a constant value that
cannot be modified during evaluation, false otherwise.
Sourcepub fn to_literal(self: Arc<Value>) -> Literal
pub fn to_literal(self: Arc<Value>) -> Literal
Get a reference to the literal representation of this value.
Returns a reference to a Literal representing this value’s type and content:
- For literal values, returns a reference to the embedded literal
- For arrays, returns the literal representation of the last element or
Literal::Emptyfor empty arrays - For all other value types, returns
Literal::Empty
This method is useful for type checking and introspection, as it provides access to the underlying literal type without consuming the value.
Sourcepub fn as_literal(self: Arc<Value>) -> Arc<Value>
pub fn as_literal(self: Arc<Value>) -> Arc<Value>
Convert this value to its literal representation.
This method consumes the value and returns the underlying literal representation:
- For literal values, returns the literal itself
- For arrays, returns the last element or
Value::Emptyfor empty arrays - For all other value types, returns
Value::Empty
Sourcepub fn is_array(&self) -> bool
pub fn is_array(&self) -> bool
Check if this value is an array.
Returns true if this value is the Array variant, false otherwise.
pub fn as_array(self: Arc<Value>) -> Arc<Value>
Sourcepub fn is_bool(&self) -> bool
pub fn is_bool(&self) -> bool
Check if this value represents a boolean.
Returns true if this value is a literal boolean, false otherwise.
Sourcepub fn as_bool(self: Arc<Value>) -> Arc<Value>
pub fn as_bool(self: Arc<Value>) -> Arc<Value>
Convert this value to a boolean representation.
Performs type conversion to boolean according to the AIMX grammar’s truthiness rules:
- Empty values: Always false
- Numbers: 0 is false, non-zero is true
- Text: Empty string is false, non-empty is true
- Dates: Always true (they exist)
- Arrays: Empty array is false, non-empty is true
- Tasks: Status determines value, no status is false
pub fn to_bool(self: Arc<Value>) -> Arc<Value>
Sourcepub fn is_date(&self) -> bool
pub fn is_date(&self) -> bool
Check if this value represents a date.
Returns true if this value is a literal date, false otherwise.
Sourcepub fn as_date(self: Arc<Value>) -> Result<Arc<Value>>
pub fn as_date(self: Arc<Value>) -> Result<Arc<Value>>
Convert this value to a date representation.
Attempts to convert the value to a date according to the AIMX grammar’s conversion rules:
- Empty values: Remain empty (no conversion needed)
- Dates: No conversion needed
- Text: Parsed as date if possible (e.g., “2023-01-01”)
- Number: Interpreted as Unix timestamp
- Boolean: true becomes Unix epoch + 1 second, false becomes Unix epoch
- Task: Text component parsed as date if possible
§Returns
Returns a Result<Value> containing the converted date value or an error
if conversion is not possible.
Sourcepub fn is_number(&self) -> bool
pub fn is_number(&self) -> bool
Check if this value represents a number.
Returns true if this value is a literal number, false otherwise.
Sourcepub fn as_number(self: Arc<Value>) -> Result<Arc<Value>>
pub fn as_number(self: Arc<Value>) -> Result<Arc<Value>>
Convert this value to a number representation.
Attempts to convert the value to a number according to the AIMX grammar’s conversion rules:
- Empty values: Remain empty (no conversion needed)
- Numbers: No conversion needed
- Text: Parsed as number if it represents a valid numeric literal (e.g., “42”, “3.14”)
- Boolean: false becomes 0, true becomes 1
- Date: Converted to Unix timestamp
- Task: Status determines value (true=1, false=-1, none=0)
§Returns
Returns a Result<Value> containing the converted number value or an error
if conversion is not possible.
Sourcepub fn to_number(&self) -> Result<f64>
pub fn to_number(&self) -> Result<f64>
Extract a numeric value from this value.
This is a convenience method for when you specifically need a f64 number.
It’s particularly useful for arithmetic operations and mathematical functions.
§Returns
Returns a Result<f64> containing the numeric value or an error if:
- The value is empty
- The value is an array with no elements
- The underlying literal cannot be converted to a number
Sourcepub fn is_task(&self) -> bool
pub fn is_task(&self) -> bool
Check if this value represents a task.
Returns true if this value is a literal task, false otherwise.
Sourcepub fn as_task(self: Arc<Value>) -> Result<Arc<Value>>
pub fn as_task(self: Arc<Value>) -> Result<Arc<Value>>
Convert this value to a task representation.
Attempts to convert the value to a task according to the AIMX grammar’s conversion rules:
- Empty values: Remain empty (no conversion needed)
- Tasks: No conversion needed
- Boolean: Status becomes the boolean value, text becomes “true”/“false”
- Date: No status, text becomes date string
- Number: Status based on sign (positive=true, negative=false, zero=none), text becomes number string
- Text: No status, text remains the same
§Returns
Returns a Result<Value> containing the converted task value or an error
if conversion is not possible.
Sourcepub fn is_text(&self) -> bool
pub fn is_text(&self) -> bool
Check if this value represents text.
Returns true if this value is a literal text, false otherwise.
Sourcepub fn as_text(self: Arc<Value>) -> Result<Arc<Value>>
pub fn as_text(self: Arc<Value>) -> Result<Arc<Value>>
Convert this value to a text representation.
Converts the value to text according to the AIMX grammar’s conversion rules:
- Empty values: Remain empty (no conversion needed)
- Text: No conversion needed
- Boolean: “true” or “false”
- Date: Formatted as ISO 8601 date string (e.g., “2023-01-01T00:00:00.000”)
- Number: Formatted as string (e.g., “42”, “3.14”)
- Task: Text component of the task (status is preserved in the Value but not in the text conversion)
§Returns
Returns a Result<Value> containing the converted text value or an error
if conversion is not possible.
pub fn to_arc_str(&self) -> Arc<str>
Sourcepub fn is_closure(&self) -> bool
pub fn is_closure(&self) -> bool
Check if this value represents a closure.
Returns true if this value is a closure, false otherwise.
Sourcepub fn is_branch(&self) -> bool
pub fn is_branch(&self) -> bool
Check if this value represents a branch.
Returns true if this value is a branch, false otherwise.
Sourcepub fn is_eval(&self) -> bool
pub fn is_eval(&self) -> bool
Check if this value represents an eval.
Returns true if this value is an eval, false otherwise.
pub fn to_pass(&self) -> Result<Value>
pub fn to_fail(&self) -> Result<Value>
Sourcepub fn is_format(&self) -> bool
pub fn is_format(&self) -> bool
Check if this value represents a format.
Returns true if this value is a format, false otherwise.
Sourcepub fn is_instance(&self) -> bool
pub fn is_instance(&self) -> bool
Check if this value represents an instance.
Returns true if this value is an instance, false otherwise.
pub fn get_instance(&self) -> Option<Instance>
Sourcepub fn is_node(&self) -> bool
pub fn is_node(&self) -> bool
Check if this value represents a node.
Returns true if this value is a node, false otherwise.
pub fn get_node(&self) -> Option<Node>
Sourcepub fn as_collection_arc(
&self,
) -> Option<Arc<HashMap<Arc<str>, Arc<Expression>>>>
pub fn as_collection_arc( &self, ) -> Option<Arc<HashMap<Arc<str>, Arc<Expression>>>>
Get Arc-wrapped collection if this is a collection value.
Returns an Arc<HashMap<String, Arc<Expression>>> if this is a collection,
allowing cheap cloning and shared access.
Sourcepub fn get_collection_ref(
&self,
) -> Option<&Arc<HashMap<Arc<str>, Arc<Expression>>>>
pub fn get_collection_ref( &self, ) -> Option<&Arc<HashMap<Arc<str>, Arc<Expression>>>>
Get Arc-wrapped collection reference if this is a collection value.
Returns a reference to the internal Arc<HashMap<String, Arc<Expression>>>
without cloning, for direct access when you need to avoid ownership transfer.
Sourcepub fn type_as_string(&self) -> &'static str
pub fn type_as_string(&self) -> &'static str
Get a string representation of this value’s type. Used to provide type information in error messages.
Returns a string indicating the type of this value based on its underlying literal representation. Possible return values are: “Empty”, “Error”, “Bool”, “Date”, “Number”, “Task”, “Text”, “Closure”, “Node”.
Sourcepub fn print(&self, writer: &mut Writer)
pub fn print(&self, writer: &mut Writer)
Write this value to the provided writer using the appropriate formatting.
This implementation delegates to the writer’s print_value method,
which handles the formatting based on the writer’s mode (string, sanitized, formula).
§Arguments
writer- The writer to write to
Sourcepub fn pretty_print(&self, prefix: &Prefix, writer: &mut Writer)
pub fn pretty_print(&self, prefix: &Prefix, writer: &mut Writer)
Print this this value using the given Prefix.
Sourcepub fn to_pretty_str(&self, prefix: Prefix) -> Arc<str>
pub fn to_pretty_str(&self, prefix: Prefix) -> Arc<str>
Format this value to a pretty string using the given Prefix.
Sourcepub fn to_formula(&self) -> String
pub fn to_formula(&self) -> String
Return the formula-string representation (round-trippable by the parser).
Trait Implementations§
Source§impl Ord for Value
impl Ord for Value
Source§impl PartialOrd for Value
impl PartialOrd for Value
Source§impl WriterLike for Value
impl WriterLike for Value
Source§fn to_stringized(&self) -> String
fn to_stringized(&self) -> String
Source§fn to_sanitized(&self) -> String
fn to_sanitized(&self) -> String
Source§fn to_expressionized(&self) -> String
fn to_expressionized(&self) -> String
impl Eq for Value
impl StructuralPartialEq for Value
Auto Trait Implementations§
impl Freeze for Value
impl RefUnwindSafe for Value
impl Send for Value
impl Sync for Value
impl Unpin 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<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.