Value

Enum Value 

Source
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

Source

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 to
  • pretty: 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");
Source

pub fn is_string(&self) -> bool

Returns true if this value is a string.

Source

pub fn is_integer(&self) -> bool

Returns true if this value is an integer.

Source

pub fn is_float(&self) -> bool

Returns true if this value is a float.

Source

pub fn is_boolean(&self) -> bool

Returns true if this value is a boolean.

Source

pub fn is_list(&self) -> bool

Returns true if this value is a list.

Source

pub fn is_map(&self) -> bool

Returns true if this value is a map.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Value

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Value

Source§

fn default() -> Value

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Value

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Value

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Value

Source§

fn eq(&self, other: &Value) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Value

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,