Skip to main content

Value

Enum Value 

Source
pub enum Value {
    Number(f64),
    String(String),
    Bool(bool),
    Nil,
    List(Vec<Value>),
    Record {
        type_name: Option<String>,
        fields: BTreeMap<String, Value>,
    },
    Color {
        r: f64,
        g: f64,
        b: f64,
        a: f64,
    },
    Result(Box<ResultValue>),
    SumVariant {
        type_name: String,
        variant: String,
        fields: Vec<Value>,
    },
    Function(StdlibFn),
}
Expand description

Runtime value in PEPL.

All PEPL values are immutable — operations that “modify” a value return a new value instead. BTreeMap is used for records to guarantee deterministic iteration order (a core PEPL invariant).

§Type names

Value::type_name returns the string used by core.type_of(): "number", "string", "bool", "nil", "list", "record" (or the declared type name for named records/sum variants), "color", "result".

Variants§

§

Number(f64)

64-bit IEEE 754 floating-point number.

NaN is prevented from entering state — operations that would produce NaN trap instead.

§

String(String)

UTF-8 string.

§

Bool(bool)

Boolean value.

§

Nil

The absence of a value.

§

List(Vec<Value>)

Ordered collection of values.

§

Record

Named fields with values. Uses BTreeMap for deterministic ordering.

type_name is Some("Todo") for named record types (type Todo = { ... }), None for anonymous inline records ({ x: 1, y: 2 }).

Fields

§type_name: Option<String>
§

Color

RGBA color value. Each component is in the range 0.0–1.0.

Fields

§

Result(Box<ResultValue>)

Result type for fallible operations (Ok or Err).

§

SumVariant

Sum type variant (e.g., Shape.Circle(5, 10)).

type_name is the declaring sum type (e.g., "Shape"). variant is the variant name (e.g., "Circle"). fields holds positional values — empty for unit variants like Active.

Fields

§type_name: String
§variant: String
§fields: Vec<Value>
§

Function(StdlibFn)

A callable function value for higher-order stdlib operations (map, filter, etc.).

Wraps an Arc<dyn Fn> so it can be cloned and passed through Vec<Value>. The evaluator creates these by wrapping PEPL lambdas/functions.

Implementations§

Source§

impl Value

Source

pub fn type_name(&self) -> &str

Returns the PEPL type name as used by core.type_of().

Source

pub fn is_truthy(&self) -> bool

Returns true if this value is truthy.

Truthiness rules (per convert.to_bool):

  • false, nil, 0, "" → falsy
  • everything else → truthy
Source

pub fn ok(self) -> Value

Convenience: wrap in Ok result.

Source

pub fn err(self) -> Value

Convenience: wrap in Err result.

Source

pub fn record(fields: BTreeMap<String, Value>) -> Value

Create an anonymous record (no type name).

Source

pub fn named_record( type_name: impl Into<String>, fields: BTreeMap<String, Value>, ) -> Value

Create a named record (e.g., type Todo = { ... }).

Source

pub fn unit_variant( type_name: impl Into<String>, variant: impl Into<String>, ) -> Value

Create a unit sum variant (no payload fields).

Source

pub fn sum_variant( type_name: impl Into<String>, variant: impl Into<String>, fields: Vec<Value>, ) -> Value

Create a sum variant with positional fields.

Source

pub fn as_number(&self) -> Option<f64>

Try to extract a number, returning None if not a Number.

Source

pub fn as_str(&self) -> Option<&str>

Try to extract a string reference, returning None if not a String.

Source

pub fn as_bool(&self) -> Option<bool>

Try to extract a bool, returning None if not a Bool.

Source

pub fn as_list(&self) -> Option<&[Value]>

Try to extract a list reference, returning None if not a List.

Source

pub fn as_record(&self) -> Option<&BTreeMap<String, Value>>

Try to extract a record reference, returning None if not a Record.

Source

pub fn as_variant(&self) -> Option<(&str, &str, &[Value])>

Try to extract sum variant info: (type_name, variant, fields).

Source

pub fn as_function(&self) -> Option<&StdlibFn>

Try to extract a function reference, returning None if not a Function.

Source

pub fn declared_type_name(&self) -> Option<&str>

Returns the declared type name for named records and sum variants. Returns None for anonymous records and all other value types.

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 Display for Value

Source§

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

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

impl From<&str> for Value

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl From<BTreeMap<String, Value>> for Value

Source§

fn from(fields: BTreeMap<String, Value>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(b: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Value

Source§

fn from(n: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(n: i64) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Value

Source§

fn eq(&self, other: &Self) -> 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.

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.