pub struct Context { /* private fields */ }Expand description
The context: always data, metadata and temp_data, in that order.
Each root starts as an object, and every write keeps it one: map,
Ctx::set and Context::set refuse anything else at a root.
Read from JSON, it takes the three roots in any order and writes them in
that order, reads a missing one as {}, takes any value at each (a
trace’s redacted root is null), and refuses any other key,
since expressions evaluate against the whole object and a fourth key
would be readable by {"var": …}. An object anywhere in it holding a key
twice is refused too: the engine reads the first, where a JSON parser
keeps the last, so the two would disagree on what the context says.
Implementations§
Source§impl Context
impl Context
Sourcepub fn data(&self) -> &OwnedDataValue
pub fn data(&self) -> &OwnedDataValue
The data root.
Sourcepub fn metadata(&self) -> &OwnedDataValue
pub fn metadata(&self) -> &OwnedDataValue
The metadata root.
Sourcepub fn temp_data(&self) -> &OwnedDataValue
pub fn temp_data(&self) -> &OwnedDataValue
The temp_data root.
Sourcepub fn as_value(&self) -> &OwnedDataValue
pub fn as_value(&self) -> &OwnedDataValue
The object holding the three roots: what expressions evaluate against.
Sourcepub fn take_data(&mut self) -> OwnedDataValue
pub fn take_data(&mut self) -> OwnedDataValue
Takes the data root, leaving an empty object where it was so the
context keeps its three roots and still serializes as one. metadata
and temp_data are untouched.
The tree is moved, not cloned: its buffers, key order and numeric representation are the ones it had, so a completed child run’s result can cross into its parent without a deep copy. A second take returns the empty object the first left.
A root that is not an object (a trace’s redacted null) is returned
as it is and replaced with {}, as every root starts as an object.