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
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));Trait Implementations§
Source§impl<'de> Deserialize<'de> for Value
impl<'de> Deserialize<'de> for Value
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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,
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