pub enum RuntimeValue {
Number(Number),
Boolean(bool),
String(Shared<String>),
Symbol(Ident),
Array(Shared<Vec<RuntimeValue>>),
Markdown(Shared<Node>, Option<Selector>),
NativeFunction(Ident),
CoroutineBuiltin(ResumeBuiltin),
Dict(Shared<DictMap>),
Bytes(Shared<Vec<u8>>),
None,
// some variants omitted
}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(Shared<String>)
A string value.
Same clone-on-write scheme as RuntimeValue::Array; see string_mut.
Symbol(Ident)
A symbol (interned identifier).
Array(Shared<Vec<RuntimeValue>>)
An array of runtime values.
Behind Shared for clone-on-write: cloning is an O(1) refcount bump; mutating
builtins must go through array_mut instead of mutating directly.
Markdown(Shared<Node>, Option<Selector>)
A markdown node with an optional selector for indexing.
Same clone-on-write scheme as RuntimeValue::Array; see markdown_mut.
NativeFunction(Ident)
A built-in native function identified by name.
CoroutineBuiltin(ResumeBuiltin)
A first-class coroutine resumption helper (next or send).
Dict(Shared<DictMap>)
A dictionary mapping identifiers to runtime values.
Same clone-on-write scheme as RuntimeValue::Array; see dict_mut.
Bytes(Shared<Vec<u8>>)
Raw binary data (e.g. CBOR byte strings).
Same clone-on-write scheme as RuntimeValue::Array; see bytes_mut.
None
An empty or null value.
Implementations§
Source§impl RuntimeValue
impl RuntimeValue
Source§impl RuntimeValue
impl RuntimeValue
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 empty_array() -> RuntimeValue
pub fn empty_array() -> RuntimeValue
Returns a new empty array.
Not a const because Shared::new (Rc/Arc::new) isn’t const-evaluable.
Sourcepub fn new_dict() -> RuntimeValue
pub fn new_dict() -> RuntimeValue
Creates a new empty dictionary.
Sourcepub fn new_markdown(node: Node) -> RuntimeValue
pub fn new_markdown(node: Node) -> RuntimeValue
Creates a new markdown runtime value from the given node.
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_coroutine(&self) -> bool
pub fn is_coroutine(&self) -> bool
Returns true if this value is a resumable coroutine.
Weak coroutine references exist only while the VM breaks internal capture cycles and
cannot be resumed by callers, so they deliberately return false here.
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 as_array(&self) -> Option<&[RuntimeValue]>
pub fn as_array(&self) -> Option<&[RuntimeValue]>
Returns the elements if this is an Array.
Sourcepub fn get(&self, key: &str) -> Option<&RuntimeValue>
pub fn get(&self, key: &str) -> Option<&RuntimeValue>
Looks up key if this is a Dict.
Sourcepub fn into_markdown_node(self) -> Option<Node>
pub fn into_markdown_node(self) -> Option<Node>
Converts to a Markdown node: markdown values keep their (selected) node, anything else
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.
Sourcepub fn strip_positions(&mut self)
pub fn strip_positions(&mut self)
Clears position information from a markdown node (recursively).
Only affects markdown values; other value types are unaffected.
Sourcepub fn strip_updated_text_position(&mut self)
pub fn strip_updated_text_position(&mut self)
Clears position only from the Text leaf written by a prior update_markdown_value
call, so the renderer won’t re-escape it. Unlike strip_positions, leaves the rest of
the tree untouched.
Sourcepub fn negated(&self) -> Self
pub fn negated(&self) -> Self
Returns a new runtime value that is the logical negation of this value.
Sourcepub fn to_json_value(self) -> Value
pub fn to_json_value(self) -> Value
Converts the value to a JSON value; unrepresentable values become null.
Sourcepub fn to_cbor_value(self) -> Value
pub fn to_cbor_value(self) -> Value
Converts the value to a CBOR value; unrepresentable values become null.
Trait Implementations§
Source§impl Clone for RuntimeValue
impl Clone for RuntimeValue
Source§impl Debug for RuntimeValue
impl Debug for RuntimeValue
Source§impl Default for RuntimeValue
impl Default for 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<DictMap> for RuntimeValue
impl From<DictMap> 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<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<Yaml> for RuntimeValue
impl From<Yaml> for RuntimeValue
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
Source§impl PartialOrd for RuntimeValue
impl PartialOrd for RuntimeValue
Source§impl ValueAdapter for RuntimeValue
impl ValueAdapter for RuntimeValue
Source§fn from_runtime_value(value: &RuntimeValue) -> Result<Self, HostFunctionError>
fn from_runtime_value(value: &RuntimeValue) -> Result<Self, HostFunctionError>
RuntimeValue argument to Self, or fails with a message describing the
expected type.Source§fn into_runtime_value(self) -> RuntimeValue
fn into_runtime_value(self) -> RuntimeValue
self into the RuntimeValue returned to mq code.Auto Trait Implementations§
impl !RefUnwindSafe for RuntimeValue
impl !Send for RuntimeValue
impl !Sync for RuntimeValue
impl !UnwindSafe for RuntimeValue
impl Forget for RuntimeValue
impl Freeze for RuntimeValue
impl Move for RuntimeValue
impl Unpin for RuntimeValue
impl UnsafeUnpin 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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