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 vendoredtimezone(chrono-tz, not the host tz database), and that serial is passed to core’sevaluate_with_resolver_at. The conversion is the determinism envelope: same instant + same timezone + same truecalc version ⇒ same serial.RAND()/RANDBETWEEN()/RANDARRAY()carry arng_seedand a per-cell key helper (Self::rng_key) implementing the ADR’sprf(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_seedis 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
impl RecalcContext
Sourcepub fn new(timestamp_ms: i64, tz: &str, rng_seed: u64) -> Option<Self>
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.
Sourcepub fn timestamp_ms(&self) -> i64
pub fn timestamp_ms(&self) -> i64
The UTC instant this context pins volatile time to (Unix milliseconds).
Sourcepub fn now_serial(&self) -> Option<f64>
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.
Sourcepub fn now_utc_nanos(&self) -> Option<i64>
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.
Sourcepub fn rng_key(
&self,
sheet_index: u32,
row: u32,
col: u32,
draw_index: u32,
) -> u64
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
impl Clone for RecalcContext
Source§fn clone(&self) -> RecalcContext
fn clone(&self) -> RecalcContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more