Skip to main content

ValueBuilder

Struct ValueBuilder 

Source
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

Source

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

Source

pub fn meter(&self) -> &Arc<Meter> ⓘ

The meter every allocation of the value is charged to.

Source

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.

Source

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.

Source

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

Source

pub fn list(&self, items: MeteredVec<Value>) -> Built

A List of items, with their vector’s charge.

Source

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.

Source

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.

Source

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

Source

pub fn finish(self, value: Built, bytes_read: i64) -> Parsed

The Parsed: value, where the read ended, the lists, and the charges of both; super::ReadBy::Boost’s, as a caller’s value is (the pure-Python reader marks its own).

Trait Implementations§

Source§

impl Debug for ValueBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.