Skip to main content

Value

Enum Value 

Source
pub enum Value {
    Number(f64),
    Text(String),
    Boolean(bool),
    Error(String),
    ErrorMsg(String, String),
    Empty,
    Array(Vec<Vec<Value>>),
    Date(f64),
    Zoned(Box<ZonedInstant>),
    Sparkline(Box<SparklineSpec>),
}
Expand description

An evaluated cell value — one of the seven types of schema spec §6.

Wire encodings extend the published @truecalc/core npm shapes: { "type": "number", "value": 1.5 }, with error using an error key ({ "error": "#REF!", "type": "error" }).

Invariants (schema spec §6 and §8):

  • Number and Date are always finite — NaN and infinity are unrepresentable; the serializer rejects them and the deserializer refuses them. -0.0 is normalized to 0.0 on deserialization, and equality/hashing treat them as the same value.
  • Array is row-major, rectangular, non-empty, larger than 1×1 (a 1×1 array is collapsed to its scalar element before storage, schema spec §6), and holds only scalar values (never a nested Array). It appears only as a spill anchor’s value (schema spec §5).
  • Sparkline plots at least two points, and its option keys are lower-case and never charttype. The serializer rejects a spec that breaks this and the deserializer refuses one, so a spec that can be written can be read.
  • Zoned is written, and must be read, as an unpadded RFC-9557 string: the wire form is canonical, even where the formula-level parsers it delegates to are lenient about casing and surrounding whitespace.

Variants§

§

Number(f64)

Finite IEEE-754 f64.

§

Text(String)

Any Unicode string.

§

Boolean(bool)

A boolean.

§

Error(String)

A spreadsheet error code, e.g. #REF!. Allowed codes are the engine’s error set for the workbook’s flavor (registry-driven).

§

ErrorMsg(String, String)

An error code carrying an additive diagnostic message (Google Sheets parity, e.g. the arity message for DATE()). The message is in-memory metadata only: it is not part of value identity (equality and hashing compare by code — see the hand-written PartialEq/Hash) and is dropped by canonical serialization, so the persisted JSON, the to_json ∘ from_json = id guarantee, and hash/equality are all byte-for-byte unchanged from a bare Error(code). Consumers read it via Value::error_message.

§

Empty

An evaluated-empty result (a formula cell before first recalc, or a formula referencing an unauthored cell). Never used to pad the sparse grid.

§

Array(Vec<Vec<Value>>)

Row-major 2-D array of scalar values; a spill anchor’s full evaluated array.

§

Date(f64)

A date as a serial number (fractional part = time of day). The epoch is implied by the workbook’s engine flavor, never stored per-value.

§

Zoned(Box<ZonedInstant>)

A zone-aware instant (Model B). Serialized as its canonical, self- describing RFC-9557 string, e.g. 2026-07-14T11:00:00+02:00[Europe/Berlin].

§

Sparkline(Box<SparklineSpec>)

A sparkline: the parsed, validated render spec produced by SPARKLINE (Google Sheets models it as a value kind of its own — TYPE() reports the undocumented code 128).

Sheets keeps two notions of sameness for a sparkline, and this type carries the deeper one. The = operator reports any two sparklines equal, whatever they plot (that is the engine’s truecalc_core::Value equality); COUNTUNIQUE nonetheless counts two different sparklines as 2 and two identical ones as 1. Storage needs the deeper notion: recalc writes a recomputed cell back only when the new value differs from the old, so if every sparkline compared equal here a changed chart would silently keep its stale spec. Equality and hashing therefore compare the whole spec, and canonical JSON carries it in full — serializing it lossily (as "", or by dropping it and recomputing from the formula) would collapse two genuinely different sparklines into one canonical form.

Implementations§

Source§

impl Value

Source

pub fn error_message(&self) -> Option<&str>

The additive diagnostic message attached to an error value, if any. Bare errors (and non-errors) return 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<'de> Deserialize<'de> for Value

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Hash for Value

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Value

Errors compare by code only — the diagnostic message is additive metadata and must never affect identity (a message-carrying error stays equal to the same bare error code, so canonical round-tripping and grid deduplication are unchanged). Every non-error arm matches the previous #[derive(PartialEq)] behaviour exactly.

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

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

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.