Skip to main content

RecalcContext

Struct RecalcContext 

Source
pub struct RecalcContext { /* private fields */ }
Expand description

The deterministic context a recalc evaluates against (scope ADR Decision 3).

Same workbook + same RecalcContext ⇒ byte-identical recomputed grid. The context is an input to recalc, never part of the workbook value or its JSON (value-object ADR): two recalcs with different contexts legitimately differ, and the property tests compare like-context runs only.

§Volatile pinning

  • NOW() / TODAY() are pinned: timestamp_ms (a UTC instant) is converted to a local spreadsheet serial against the vendored timezone (chrono-tz, not the host tz database), and that serial is passed to core’s evaluate_with_resolver_at. The conversion is the determinism envelope: same instant + same timezone + same truecalc version ⇒ same serial.
  • RAND() / RANDBETWEEN() / RANDARRAY() carry a rng_seed and a per-cell key helper (Self::rng_key) implementing the ADR’s prf(seed, sheet_index, row, col, draw_index) scheme. Caveat: core’s RNG functions presently read the system clock directly and take no per-cell key (crates/core/.../math/rand), so the workbook layer cannot yet inject this seed into them — full PRF-keyed RNG determinism requires a core change and is tracked for P4. rng_seed is carried now so the API is stable; recalc therefore guarantees determinism for non-RNG workbooks (which is every P3.6 fixture).

Implementations§

Source§

impl RecalcContext

Source

pub fn new(timestamp_ms: i64, tz: &str, rng_seed: u64) -> Option<Self>

Builds a context from a UTC instant (Unix milliseconds), an IANA timezone id (e.g. "Etc/GMT", "America/New_York"), and an RNG seed.

Returns None if tz is not a known IANA id in the vendored database.

Source

pub fn timestamp_ms(&self) -> i64

The UTC instant this context pins volatile time to (Unix milliseconds).

Source

pub fn timezone(&self) -> Tz

The vendored IANA timezone the instant is localized against.

Source

pub fn rng_seed(&self) -> u64

The RNG seed keying deterministic per-cell draws.

Source

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

The local spreadsheet serial datetime this context pins NOW()/TODAY() to: the UTC timestamp_ms rendered into timezone, expressed as days since the 1899-12-30 epoch (integer part) plus time-of-day (fraction) — the now_serial core’s evaluate_at family consumes.

Returns None only if the instant is unrepresentable (e.g. out of chrono’s range), which cannot happen for any realistic timestamp.

Source

pub fn now_utc_nanos(&self) -> Option<i64>

The pinned “now” as an absolute UTC instant in nanoseconds, for the zone-aware TZNOW. Derived from the same timestamp_ms as now_serial, so NOW() and TZNOW() share one deterministic clock.

Source

pub fn rng_key( &self, sheet_index: u32, row: u32, col: u32, draw_index: u32, ) -> u64

The ADR’s per-draw RNG key prf(rng_seed, sheet_index, row, col, draw_index), a deterministic, order-independent mixing of the cell identity into the seed.

Exposed (and unit-tested) so the keying scheme is fixed and ready for the core integration that will consume it; see the type-level caveat.

Trait Implementations§

Source§

impl Clone for RecalcContext

Source§

fn clone(&self) -> RecalcContext

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 RecalcContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for RecalcContext

Source§

impl PartialEq for RecalcContext

Source§

fn eq(&self, other: &RecalcContext) -> bool

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for RecalcContext

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