Skip to main content

Value

Enum Value 

Source
pub enum Value {
    Void,
    Scalar(f64),
    Matrix(Array2<f64>),
    Complex(f64, f64),
    Str(String),
    StringObj(String),
    Lambda(LambdaFn),
    Function {
        outputs: Vec<String>,
        params: Vec<String>,
        body_source: String,
        locals: IndexMap<String, Value>,
        doc: Option<String>,
    },
    Tuple(Vec<Value>),
    Cell(Vec<Value>),
    Struct(IndexMap<String, Value>),
    StructArray(Vec<IndexMap<String, Value>>),
}
Expand description

A value held in the variable environment.

Variants§

§

Void

No display value — returned by side-effectful functions like fprintf.

§

Scalar(f64)

A single real number.

§

Matrix(Array2<f64>)

A 2-D real matrix (row-major). Scalars are represented as 1×1 matrices only when produced by matrix operations; standalone numbers use Scalar.

§

Complex(f64, f64)

Complex number re + im*i.

§

Str(String)

Character array (single-quoted string). Represents a 1×N row of char values.

§

StringObj(String)

String object (double-quoted string).

§

Lambda(LambdaFn)

Anonymous function: @(params) expr. Stores a pre-compiled closure that captures the lexical environment at definition time.

§

Function

Named user-defined function: function [outputs] = name(params) ... end.

The body is stored as raw source text and re-parsed on each call. Named functions execute in an isolated scope (only params are visible, plus built-in constants i, j).

Fields

§outputs: Vec<String>

Output variable names in declaration order (e.g. ["y"] for function y = f(x)).

§params: Vec<String>

Parameter names in declaration order (e.g. ["x", "n"]).

§body_source: String

Raw source text of the function body (text between function header and end).

§locals: IndexMap<String, Value>

Local helper functions defined in the same function file (MATLAB-style scoping). Populated when a function file is sourced; empty for inline definitions.

§doc: Option<String>

Documentation string extracted from %-prefixed lines immediately before the function keyword. None when no leading comment block is present.

§

Tuple(Vec<Value>)

Multiple return values from a multi-output function call (internal use).

Produced by calling a function with outputs.len() > 1. Consumed by Stmt::MultiAssign in exec.rs. Not directly user-visible.

§

Cell(Vec<Value>)

Heterogeneous 1-D container: each element may be any Value.

Created with {1, 'hello', [1 2 3]} syntax. Indexed with c{i} (1-based). 2-D cell arrays are deferred; all cells are flat Vec<Value> for now.

§

Struct(IndexMap<String, Value>)

Scalar struct: ordered field map, field names preserved in insertion order.

Created with s.field = val or struct('k', v, ...). Fields can hold any Value, including nested structs.

§

StructArray(Vec<IndexMap<String, Value>>)

1-D array of structs (all sharing the same field schema).

Created with s(i).field = val (1-based). Indexed with s(i) which returns a Value::Struct. s.field collects the field across all elements.

Implementations§

Source§

impl Value

Source

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

Returns the inner f64 if this value is a Value::Scalar, otherwise None.

§Examples
use ccalc_engine::env::Value;

assert_eq!(Value::Scalar(3.14).as_scalar(), Some(3.14));
assert_eq!(Value::Void.as_scalar(), None);

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

Source§

fn eq(&self, other: &Value) -> 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 StructuralPartialEq for Value

Auto Trait Implementations§

§

impl Freeze for Value

§

impl !RefUnwindSafe for Value

§

impl !Send for Value

§

impl !Sync for Value

§

impl Unpin for Value

§

impl UnsafeUnpin 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, 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V