pub enum Value {
Null,
Bool(bool),
Int(i64),
Float(f64),
String(Box<str>),
Tensor(Box<Tensor>),
Reference(Reference),
Expression(Box<Expression>),
List(Box<Vec<Value>>),
}Expand description
Re-export core types for convenience. A scalar value in HEDL.
Optimized memory layout:
- Large variants (String, Tensor, Expression, List) are boxed to keep enum size small
- Small values (Null, Bool, Int, Float) remain inline
- Total enum size: 16 bytes (down from 32+ bytes)
- Reduces memory usage by 40-50% for typical documents
Variants§
Null
Null value (~).
Bool(bool)
Boolean value (true/false).
Int(i64)
Integer value.
Float(f64)
Floating-point value.
String(Box<str>)
String value (boxed to reduce enum size).
Tensor(Box<Tensor>)
Tensor (multi-dimensional array, boxed to reduce enum size).
Reference(Reference)
Reference to another node.
Expression(Box<Expression>)
Parsed expression from $(…) (boxed to reduce enum size).
List(Box<Vec<Value>>)
List of scalar values (from (...) syntax).
Distinct from Tensor: lists can contain any scalar types (strings, bools, refs, etc.), while tensors are numeric-only.
§Examples
use hedl_core::Value;
// String list: (admin, editor, viewer)
let roles = Value::List(Box::new(vec![
Value::String("admin".into()),
Value::String("editor".into()),
Value::String("viewer".into()),
]));
// Bool list: (true, false, true)
let flags = Value::List(Box::new(vec![
Value::Bool(true),
Value::Bool(false),
Value::Bool(true),
]));
// Empty list: ()
let empty = Value::List(Box::new(vec![]));Implementations§
Source§impl Value
impl Value
Sourcepub fn is_reference(&self) -> bool
pub fn is_reference(&self) -> bool
Returns true if this value is a reference.
Sourcepub fn as_reference(&self) -> Option<&Reference>
pub fn as_reference(&self) -> Option<&Reference>
Try to get the value as a reference.
Source§impl Value
impl Value
Sourcepub fn as_expression(&self) -> Option<&Expression>
pub fn as_expression(&self) -> Option<&Expression>
Try to get the expression if this is an Expression variant.
Sourcepub fn coerce_to(&self, expected: &ExpectedType) -> CoercionResult
pub fn coerce_to(&self, expected: &ExpectedType) -> CoercionResult
Attempt to coerce this value to the expected type.
Uses lenient mode (equivalent to Standard level) by default.
§Examples
use hedl_core::Value;
use hedl_core::types::ExpectedType;
let value = Value::String("42".to_string().into());
let result = value.coerce_to(&ExpectedType::Int);
assert!(result.is_ok());Sourcepub fn can_coerce_to(&self, expected: &ExpectedType) -> bool
pub fn can_coerce_to(&self, expected: &ExpectedType) -> bool
Check if this value can be coerced to the expected type.
Returns true if coercion would succeed (either matched or coerced).
§Examples
use hedl_core::Value;
use hedl_core::types::ExpectedType;
let value = Value::Int(42);
assert!(value.can_coerce_to(&ExpectedType::Float));
let value = Value::String("42".to_string().into());
assert!(value.can_coerce_to(&ExpectedType::Int));