pub enum Value {
Null,
Bool(bool),
Int(i64),
Float(f64),
String(Box<str>),
Tensor(Box<Tensor>),
Reference(Reference),
Expression(Box<Expression>),
}Expand description
Re-export core types for convenience. A scalar value in HEDL.
Optimized memory layout:
- Large variants (String, Tensor, Expression) 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).
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));Trait Implementations§
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
Mutably borrows from an owned value. Read more