pub struct ValueBuilder { /* private fields */ }Expand description
Builds one object’s value on its input’s meter: the reader’s only way to
make a Parsed (plan section 3.10).
Every list, map, tuple and primitive run the reader makes grows in a
MeteredVec from Self::vec, so its capacity is charged before it
is allocated, and is turned into a Built here, which carries its
charge into its parent and on into the Parsed. The table of node lists
(Parsed::lists) grows the same way. The builder keeps no value’s
charge, so dropping it (a read that failed) leaves nothing uncharged.
Implementations§
Source§impl ValueBuilder
impl ValueBuilder
Sourcepub fn new(meter: &Arc<Meter>, root: SharedNodes) -> Result<Self, ChargeError>
pub fn new(meter: &Arc<Meter>, root: SharedNodes) -> Result<Self, ChargeError>
A builder charging meter, whose first node list is root (the tree
the object is read with).
Sourcepub fn vec<T>(&self) -> MeteredVec<T>
pub fn vec<T>(&self) -> MeteredVec<T>
An empty vector on the meter, for a list, a map’s entries, a tuple or a run.
Sourcepub fn list_index(&mut self, list: &SharedNodes) -> Result<ListIx, ChargeError>
pub fn list_index(&mut self, list: &SharedNodes) -> Result<ListIx, ChargeError>
The index of list in the value’s lists, appending it the first time
(deduplicated by Arc pointer: one entry per distinct ref-type tree).
The first eight are found by a scan, the rest by a table
from each list’s address, so a read of n references into n ref
types finds them in steps linear in n (claude X, review round 2: a
scan of every list made it n²). The lists’ and the table’s growth
are charged; past u32 it is LimitKind::Count.
Sourcepub fn scalar(&self, value: Value) -> Result<Built, Value>
pub fn scalar(&self, value: Value) -> Result<Built, Value>
A value that owns no heap of its own (a scalar, a string or bytes
sliced from a charged buffer, an empty list or map), as a Built
with an empty charge; a list, map, tuple or run that owns an
allocation is handed back, since only the builder’s own methods know
what it was charged. A Str or Bytes is taken as it is: it must be
a slice of a charged buffer (the file’s, crate::RawStr::charged,
a decoded block’s), never one made from a Vec no meter charged,
which this cannot see (module docs).
Sourcepub fn list(&self, items: MeteredVec<Value>) -> Built
pub fn list(&self, items: MeteredVec<Value>) -> Built
A List of items, with their vector’s charge.
Sourcepub fn map(&self, list: ListIx, entries: MeteredVec<(NodeId, Value)>) -> Built
pub fn map(&self, list: ListIx, entries: MeteredVec<(NodeId, Value)>) -> Built
A Dict whose keys name nodes of list list, over entries with
distinct keys, with their vector’s charge.
Sourcepub fn tuple(&self, items: MeteredVec<Value>) -> Result<Built, ChargeError>
pub fn tuple(&self, items: MeteredVec<Value>) -> Result<Built, ChargeError>
A Tuple of items, moved into an exact allocation that is charged
first (MeteredVec::into_boxed_slice), with its charge.
Sourcepub fn prims(&self, run: PrimRun) -> Result<Built, ChargeError>
pub fn prims(&self, run: PrimRun) -> Result<Built, ChargeError>
A Prims value of run, moved into an exact allocation that is
charged first, with its charge. (vector<UInt8>/char is a
zero-copy slice of the file, PrimArray::U8, through
Self::scalar.)