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
impl RuntimeValue
Sourcepub const EMPTY_ARRAY: RuntimeValue
pub const EMPTY_ARRAY: RuntimeValue
An empty array constant.
Sourcepub const FALSE: RuntimeValue
pub const FALSE: RuntimeValue
The boolean false value.
Sourcepub const NONE: RuntimeValue = Self::None
pub const NONE: RuntimeValue = Self::None
The None (null) value.
Sourcepub const TRUE: RuntimeValue
pub const TRUE: RuntimeValue
The boolean true value.
Sourcepub fn new_dict() -> RuntimeValue
pub fn new_dict() -> RuntimeValue
Creates a new empty dictionary.
Sourcepub fn is_function(&self) -> bool
pub fn is_function(&self) -> bool
Returns true if this value is a user-defined function.
Sourcepub fn is_native_function(&self) -> bool
pub fn is_native_function(&self) -> bool
Returns true if this value is a native (built-in) function.
Sourcepub fn is_empty(&self) -> bool
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.
Sourcepub fn is_truthy(&self) -> bool
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.
Sourcepub fn len(&self) -> usize
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.
Sourcepub fn markdown_node(&self) -> Option<Node>
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.
Sourcepub fn update_markdown_value(&self, value: &str) -> RuntimeValue
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.
Sourcepub fn position(&self) -> Option<Position>
pub fn position(&self) -> Option<Position>
Returns the position information for a markdown node, if available.
Sourcepub fn set_position(&mut self, position: Option<Position>)
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
impl Clone for RuntimeValue
Source§fn clone(&self) -> RuntimeValue
fn clone(&self) -> RuntimeValue
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RuntimeValue
impl Debug for RuntimeValue
Source§impl Default for RuntimeValue
impl Default for RuntimeValue
Source§fn default() -> RuntimeValue
fn default() -> RuntimeValue
Source§impl Display for RuntimeValue
impl Display for RuntimeValue
Source§impl From<&mut str> for RuntimeValue
impl From<&mut str> for RuntimeValue
Source§impl From<&str> for RuntimeValue
impl From<&str> for RuntimeValue
Source§impl From<AttrValue> for RuntimeValue
impl From<AttrValue> for RuntimeValue
Source§impl From<BTreeMap<Ident, RuntimeValue>> for RuntimeValue
impl From<BTreeMap<Ident, RuntimeValue>> for RuntimeValue
Source§impl From<Ident> for RuntimeValue
impl From<Ident> for RuntimeValue
Source§impl From<Node> for RuntimeValue
impl From<Node> for RuntimeValue
Source§impl From<String> for RuntimeValue
impl From<String> for RuntimeValue
Source§impl From<Value> for RuntimeValue
impl From<Value> for RuntimeValue
Source§impl From<Vec<RuntimeValue>> for RuntimeValue
impl From<Vec<RuntimeValue>> for RuntimeValue
Source§fn from(arr: Vec<RuntimeValue>) -> Self
fn from(arr: Vec<RuntimeValue>) -> Self
Source§impl From<bool> for RuntimeValue
impl From<bool> for RuntimeValue
Source§impl From<usize> for RuntimeValue
impl From<usize> for RuntimeValue
Source§impl PartialEq for RuntimeValue
impl PartialEq for RuntimeValue
Auto Trait Implementations§
impl Freeze for RuntimeValue
impl !RefUnwindSafe for RuntimeValue
impl !Send for RuntimeValue
impl !Sync for RuntimeValue
impl Unpin for RuntimeValue
impl UnsafeUnpin for RuntimeValue
impl !UnwindSafe for RuntimeValue
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