Skip to main content

RuntimeValue

Enum RuntimeValue 

Source
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

Source

pub fn sort_cmp(&self, other: &Self) -> Ordering

Total order for sort/sort_by: same types use partial_cmp, mixed types are ordered by type.

Source§

impl RuntimeValue

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 empty_array() -> RuntimeValue

Returns a new empty array.

Not a const because Shared::new (Rc/Arc::new) isn’t const-evaluable.

Source

pub fn new_dict() -> RuntimeValue

Creates a new empty dictionary.

Source

pub fn new_markdown(node: Node) -> RuntimeValue

Creates a new markdown runtime value from the given node.

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_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.

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_dict(&self) -> bool

Returns true if this value is a dict.

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 as_str(&self) -> Option<&str>

Returns the string if this is a String.

Source

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

Returns the number if this is a Number.

Source

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

Returns the boolean if this is a Boolean.

Source

pub fn as_array(&self) -> Option<&[RuntimeValue]>

Returns the elements if this is an Array.

Source

pub fn as_dict(&self) -> Option<&DictMap>

Returns the entries if this is a Dict.

Source

pub fn get(&self, key: &str) -> Option<&RuntimeValue>

Looks up key if this is a Dict.

Source

pub fn into_markdown_node(self) -> Option<Node>

Converts to a Markdown node: markdown values keep their (selected) node, anything else

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.

Source

pub fn strip_positions(&mut self)

Clears position information from a markdown node (recursively).

Only affects markdown values; other value types are unaffected.

Source

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.

Source

pub fn negated(&self) -> Self

Returns a new runtime value that is the logical negation of this value.

Source

pub fn to_json_value(self) -> Value

Converts the value to a JSON value; unrepresentable values become null.

Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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() -> Self

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<DictMap> for RuntimeValue

Source§

fn from(map: DictMap) -> 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<Rc<String>> for RuntimeValue

Source§

fn from(s: Shared<String>) -> Self

Converts to this type from the input type.
Source§

impl From<Rc<Vec<u8>>> for RuntimeValue

Source§

fn from(b: Shared<Vec<u8>>) -> 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<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<Vec<u8>> for RuntimeValue

Source§

fn from(b: Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<Yaml> for RuntimeValue

Source§

fn from(value: Yaml) -> 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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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
Source§

impl ValueAdapter for RuntimeValue

Source§

fn from_runtime_value(value: &RuntimeValue) -> Result<Self, HostFunctionError>

Converts a RuntimeValue argument to Self, or fails with a message describing the expected type.
Source§

fn into_runtime_value(self) -> RuntimeValue

Converts self into the RuntimeValue returned to mq code.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.