Skip to main content

Context

Struct Context 

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

Source

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.

Source

pub fn empty() -> Self

Create an empty Context with no variable bindings.

Source

pub fn get(&self, name: &str) -> Value

Look up a variable by name (case-insensitive). Returns Value::Empty if not found.

Source

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.

Source

pub fn set(&mut self, name: String, value: Value) -> Option<Value>

Insert or overwrite a binding. Returns the previous value if one existed.

Source

pub fn remove(&mut self, name: &str)

Remove a binding. Used to restore context after lambda/let evaluation.

Source

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

Source

pub fn draw_rand_n(&self, count: usize) -> Vec<f64>

Draw count values in [0,1), each using its own draw_index.

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