Skip to main content

Value

Enum Value 

Source
pub enum Value {
Show 18 variants Void, Scalar(f64), Matrix(Box<Array2<f64>>), ComplexMatrix(Box<Array2<Complex<f64>>>), Complex(f64, f64), Str(String), StringObj(String), Lambda(Box<LambdaFn>), Function(Box<FunctionData>), Tuple(Vec<Value>), Cell(Box<Vec<Value>>), Struct(Box<IndexMap<String, Value>>), StructArray(Box<Vec<IndexMap<String, Value>>>), DateTime(f64), Duration(f64), DateTimeArray(Vec<f64>), DurationArray(Vec<f64>), Map(Box<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(Box<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.

§

ComplexMatrix(Box<Array2<Complex<f64>>>)

A 2-D complex matrix (row-major). Used when any element has a non-zero imaginary part.

Produced by complex matrix literals, FFT output, or mixed real/complex arithmetic. Workspace save skips this type (same policy as all non-scalar types).

§

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(Box<LambdaFn>)

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

§

Function(Box<FunctionData>)

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

All fields are stored in a Boxed FunctionData to keep Value at 32 bytes.

§

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(Box<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(Box<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(Box<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.

§

DateTime(f64)

A UTC timestamp: seconds since 1970-01-01 00:00:00 UTC.

f64::NAN represents the NaT (Not-a-Time) sentinel.

§

Duration(f64)

An elapsed duration stored as a fractional number of seconds.

May be negative (e.g. t1 - t2 when t1 < t2).

§

DateTimeArray(Vec<f64>)

An ordered sequence of UTC timestamps (seconds since epoch).

Each element follows the same NaT-as-NaN convention as Value::DateTime.

§

DurationArray(Vec<f64>)

An ordered sequence of elapsed durations (seconds, fractional).

§

Map(Box<IndexMap<String, Value>>)

String-keyed associative array (containers.Map semantics).

Keys are always String; values may be any Value. Preserves insertion order (via IndexMap). Indexed with m('key') and assigned with m('key') = val.

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 (const: unstable) · 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 From<FunctionData> for Value

Source§

fn from(fd: FunctionData) -> Self

Converts to this type from the input type.
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 (const: unstable) · 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