pub struct Context {
pub vars: HashMap<String, Value>,
pub now_serial: Option<f64>,
pub now_utc_nanos: Option<i64>,
pub rng_cell: Option<(u64, u32, u32, u32)>,
}Expand description
Holds the named variable bindings for a formula evaluation.
All keys are stored and looked up in uppercase, so variable names are
case-insensitive (A1, a1, and A1 all refer to the same binding).
Fields§
§vars: HashMap<String, Value>§now_serial: Option<f64>Pinned “now” for volatile date functions (NOW, TODAY), as a
local-time spreadsheet serial datetime (integer part = day serial,
fraction = time of day). None ⇒ the functions read the ambient
local clock. Set via crate::Engine::evaluate_at (P1.4, issue #526).
now_utc_nanos: Option<i64>Pinned “now” as an absolute UTC instant (nanoseconds since the Unix
epoch), for the zone-aware TZNOW. None ⇒ TZNOW reads the ambient
UTC clock. Set from the workbook’s timestamp_ms during recalc; distinct
from now_serial (a tz-naive local serial for NOW/TODAY).
rng_cell: Option<(u64, u32, u32, u32)>Per-cell RNG key for deterministic draws: (seed, sheet_index, row, col). Set by the workbook recalc loop; None for bare Engine::evaluate calls.
Implementations§
Source§impl Context
impl Context
Sourcepub fn new(vars: HashMap<String, Value>) -> Self
pub fn new(vars: HashMap<String, Value>) -> Self
Create a Context from a map of variable name → value.
Keys are normalised to uppercase on insertion.
Sourcepub fn get(&self, name: &str) -> Value
pub fn get(&self, name: &str) -> Value
Look up a variable by name (case-insensitive). Returns Value::Empty if not found.
Sourcepub fn lookup(&self, name: &str) -> Option<Value>
pub fn lookup(&self, name: &str) -> Option<Value>
Look up a binding by name (case-insensitive), distinguishing an absent
binding (None) from one explicitly bound to Value::Empty
(Some(Value::Empty)). Used by the evaluator to decide whether a
reference should fall through to the resolver.
Sourcepub fn set(&mut self, name: String, value: Value) -> Option<Value>
pub fn set(&mut self, name: String, value: Value) -> Option<Value>
Insert or overwrite a binding. Returns the previous value if one existed.
Sourcepub fn remove(&mut self, name: &str)
pub fn remove(&mut self, name: &str)
Remove a binding. Used to restore context after lambda/let evaluation.
Sourcepub fn draw_rand(&self, draw_index: u32) -> f64
pub fn draw_rand(&self, draw_index: u32) -> f64
SplitMix64-based PRF: draw a value in [0,1) for the given draw index. Uses the per-cell key when available; falls back to SystemTime for bare Engine::evaluate calls (non-deterministic).
Sourcepub fn draw_rand_n(&self, count: usize) -> Vec<f64>
pub fn draw_rand_n(&self, count: usize) -> Vec<f64>
Draw count values in [0,1), each using its own draw_index.