Skip to main content

RuntimeValue

Enum RuntimeValue 

Source
pub enum RuntimeValue {
    Number(Number),
    Boolean(bool),
    String(String),
    Symbol(Ident),
    Array(Vec<RuntimeValue>),
    Markdown(Node, Option<Selector>),
    Function(AstParams, Program, Shared<SharedCell<Env>>),
    NativeFunction(Ident),
    Dict(BTreeMap<Ident, RuntimeValue>),
    Module(ModuleEnv),
    Ast(Shared<Node>),
    None,
}
Expand description

A value in the mq runtime.

This enum represents all possible value types that can exist during program execution, including numbers, strings, markdown nodes, functions, and more complex data structures.

Variants§

§

Number(Number)

A numeric value.

§

Boolean(bool)

A boolean value (true or false).

§

String(String)

A string value.

§

Symbol(Ident)

A symbol (interned identifier).

§

Array(Vec<RuntimeValue>)

An array of runtime values.

§

Markdown(Node, Option<Selector>)

A markdown node with an optional selector for indexing.

§

Function(AstParams, Program, Shared<SharedCell<Env>>)

A user-defined function with parameters, body (program), and captured environment.

§

NativeFunction(Ident)

A built-in native function identified by name.

§

Dict(BTreeMap<Ident, RuntimeValue>)

A dictionary mapping identifiers to runtime values.

§

Module(ModuleEnv)

A module with its exports.

§

Ast(Shared<Node>)

An AST node (quoted expression).

§

None

An empty or null value.

Implementations§

Source§

impl RuntimeValue

Source

pub const EMPTY_ARRAY: RuntimeValue

An empty array constant.

Source

pub const FALSE: RuntimeValue

The boolean false value.

Source

pub const NONE: RuntimeValue = Self::None

The None (null) value.

Source

pub const TRUE: RuntimeValue

The boolean true value.

Source

pub fn new_dict() -> RuntimeValue

Creates a new empty dictionary.

Source

pub fn name(&self) -> &str

Returns the type name of this runtime value as a string.

Source

pub fn is_none(&self) -> bool

Returns true if this value is None.

Source

pub fn is_function(&self) -> bool

Returns true if this value is a user-defined function.

Source

pub fn is_native_function(&self) -> bool

Returns true if this value is a native (built-in) function.

Source

pub fn is_array(&self) -> bool

Returns true if this value is an array.

Source

pub fn is_empty(&self) -> bool

Returns true if this value is considered empty.

Empty values include empty arrays, empty strings, empty markdown nodes, empty dictionaries, and None.

Source

pub fn is_truthy(&self) -> bool

Returns true if this value is considered truthy in conditional contexts.

Truthy values include non-zero numbers, non-empty strings and arrays, true, functions, symbols, and modules. Falsy values include false, zero, empty collections, and None.

Source

pub fn len(&self) -> usize

Returns the length of this value.

For numbers, returns the value as usize. For strings and arrays, returns the number of elements. For dictionaries, returns the number of entries.

Source

pub fn markdown_node(&self) -> Option<Node>

Extracts the markdown node from this value, if it is a markdown value.

If a selector is present, returns the selected child node.

Source

pub fn update_markdown_value(&self, value: &str) -> RuntimeValue

Updates the value of a markdown node, returning a new runtime value.

If this is not a markdown value, returns None.

Source

pub fn position(&self) -> Option<Position>

Returns the position information for a markdown node, if available.

Source

pub fn set_position(&mut self, position: Option<Position>)

Sets the position information for a markdown node.

Only affects markdown values; other value types are unaffected.

Trait Implementations§

Source§

impl Clone for RuntimeValue

Source§

fn clone(&self) -> RuntimeValue

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 RuntimeValue

Source§

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

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

impl Default for RuntimeValue

Source§

fn default() -> RuntimeValue

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

impl Display for RuntimeValue

Source§

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

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

impl From<&mut str> for RuntimeValue

Source§

fn from(s: &mut str) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for RuntimeValue

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl From<AttrValue> for RuntimeValue

Source§

fn from(attr_value: AttrValue) -> Self

Converts to this type from the input type.
Source§

impl From<BTreeMap<Ident, RuntimeValue>> for RuntimeValue

Source§

fn from(map: BTreeMap<Ident, RuntimeValue>) -> Self

Converts to this type from the input type.
Source§

impl From<Ident> for RuntimeValue

Source§

fn from(i: Ident) -> Self

Converts to this type from the input type.
Source§

impl From<Node> for RuntimeValue

Source§

fn from(node: Node) -> Self

Converts to this type from the input type.
Source§

impl From<String> for RuntimeValue

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl From<Value> for RuntimeValue

Source§

fn from(value: Value) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<(String, Number)>> for RuntimeValue

Source§

fn from(v: Vec<(String, Number)>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<RuntimeValue>> for RuntimeValue

Source§

fn from(arr: Vec<RuntimeValue>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for RuntimeValue

Source§

fn from(b: bool) -> Self

Converts to this type from the input type.
Source§

impl From<usize> for RuntimeValue

Source§

fn from(n: usize) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for RuntimeValue

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.
Source§

impl PartialOrd for RuntimeValue

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
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> ToSmolStr for T
where T: Display + ?Sized,

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.