pub enum Value {
Null,
String(String),
Integer(i64),
Float(f64),
Boolean(bool),
List(Vec<Value>),
Map(BTreeMap<String, Value>),
}
Expand description
Represents the final output values produced by the RESL language interpreter.
Values are the end result of evaluating RESL expressions - they are what your RESL programs ultimately produce. Every expression in RESL evaluates to one of these value types. Values can be serialized/deserialized for data interchange and support formatted output with pretty-printing.
§Examples
use resl::{Value, evaluate};
// Final outputs from RESL expressions
let result1 = evaluate("null").unwrap();
assert_eq!(result1, Value::Null);
let result2 = evaluate("\"Hello, World!\"").unwrap();
assert_eq!(result2, Value::String("Hello, World!".to_string()));
let result3 = evaluate("(5 + 3)").unwrap();
assert_eq!(result3, Value::Integer(8));
let result4 = evaluate("(3.14 * 2.0)").unwrap();
assert_eq!(result4, Value::Float(6.28));
// Operations can also be enclosed in parentheses
let result_paren = evaluate("(10 - 2)").unwrap();
assert_eq!(result_paren, Value::Integer(8));
let result5 = evaluate("[1, 2, 3]").unwrap();
assert_eq!(result5, Value::List(vec![
Value::Integer(1),
Value::Integer(2),
Value::Integer(3),
]));
let result6 = evaluate("[\"name\": \"Alice\", \"age\": 30]").unwrap();
// This produces a Value::Map containing the key-value pairs
Variants§
Null
The null output value, representing the absence of meaningful data.
This is produced by expressions that evaluate to nothing, null literals, or operations that don’t return a meaningful result.
§RESL Expressions that produce Null
null
String(String)
A Unicode string output value.
This is the final result when RESL expressions produce text data. String literals use double quotes and support standard escape sequences.
§RESL Expressions that produce String
"Hello, World!"
"Line 1\nLine 2"
Integer(i64)
A 64-bit signed integer output value.
This is produced by integer literals, arithmetic operations that yield whole numbers, or other expressions that evaluate to integers.
§RESL Expressions that produce Integer
42
-17 // Negative integer
0
9223372036854775807
(5 + 3) // Binary operations with parentheses
(- 42) // Unary operations
Float(f64)
A 64-bit floating-point output value.
This is produced by float literals, floating-point arithmetic, or operations that yield fractional numbers.
§RESL Expressions that produce Decimal
3.14159
-2.5
0.0
(3.14 * 2.0) // Binary operations
(- 3.14) // Unary operations
Boolean(bool)
A boolean output value representing true or false.
This is the result of logical operations, comparisons, or boolean literals.
§RESL Expressions that produce Boolean
true
false
(5 > 3) // Comparison operations with parentheses
10 == 10 // Comparison operations without parentheses
(! false) // Unary logical operations with parentheses
List(Vec<Value>)
An ordered list output value containing multiple values.
This is produced by list literals or operations that generate collections. Lists can contain any mix of value types, including nested structures.
§RESL Expressions that produce List
[1, 2, 3]
["apple", "banana", "cherry"]
[true, false, null]
[1, "mixed", [2, 3]]
[]
Map(BTreeMap<String, Value>)
An associative map output value with string keys and arbitrary values.
This is produced by map literals or operations that generate key-value
associations. Maps use string keys and can contain any mix of value types.
The ordering depends on the preserve-order
feature flag.
§RESL Expressions that produce Map
["name": "Alice", "age": 30]
["x": 10, "y": 20, "visible": true]
["data": ["nested": "value"]]
Implementations§
Source§impl Value
impl Value
Sourcepub fn write_formatted<W: Write>(&self, writer: &mut W, pretty: bool) -> Result
pub fn write_formatted<W: Write>(&self, writer: &mut W, pretty: bool) -> Result
Writes a formatted representation of this value to a writer.
This is a convenience method that calls format
with an indent level of 0.
§Parameters
writer
: The writer to output formatted content topretty
: Whether to use pretty-printing with newlines and indentation
§Examples
use resl::Value;
let value = Value::Integer(42);
let mut output = String::new();
value.write_formatted(&mut output, false).unwrap();
assert_eq!(output, "42");
Sourcepub fn is_integer(&self) -> bool
pub fn is_integer(&self) -> bool
Returns true
if this value is an integer.
Sourcepub fn is_boolean(&self) -> bool
pub fn is_boolean(&self) -> bool
Returns true
if this value is a boolean.