Enum ParentState

Source
enum ParentState<'a> {
    Variant {
        buffer: &'a mut ValueBuffer,
        metadata_builder: &'a mut MetadataBuilder,
    },
    List {
        buffer: &'a mut ValueBuffer,
        metadata_builder: &'a mut MetadataBuilder,
        offsets: &'a mut Vec<usize>,
    },
    Object {
        buffer: &'a mut ValueBuffer,
        metadata_builder: &'a mut MetadataBuilder,
        fields: &'a mut IndexMap<u32, usize>,
        field_name: &'a str,
    },
}
Expand description

Tracks information needed to correctly finalize a nested builder, for each parent builder type.

A child builder has no effect on its parent unless/until its finalize method is called, at which point the child appends the new value to the parent. As a (desirable) side effect, creating a parent state instance captures mutable references to a subset of the parent’s fields, rendering the parent object completely unusable until the parent state goes out of scope. This ensures that at most one child builder can exist at a time.

The redundancy in buffer and metadata_builder is because all the references come from the parent, and we cannot “split” a mutable reference across two objects (parent state and the child builder that uses it). So everything has to be here. Rust layout optimizations should treat the variants as a union, so that accessing a buffer or metadata_builder is branch-free.

Variants§

§

Variant

Fields

§buffer: &'a mut ValueBuffer
§metadata_builder: &'a mut MetadataBuilder
§

List

Fields

§buffer: &'a mut ValueBuffer
§metadata_builder: &'a mut MetadataBuilder
§offsets: &'a mut Vec<usize>
§

Object

Fields

§buffer: &'a mut ValueBuffer
§metadata_builder: &'a mut MetadataBuilder
§fields: &'a mut IndexMap<u32, usize>
§field_name: &'a str

Implementations§

Source§

impl ParentState<'_>

Source

fn buffer(&mut self) -> &mut ValueBuffer

Source

fn metadata_builder(&mut self) -> &mut MetadataBuilder

Source

fn finish(&mut self, starting_offset: usize)

Auto Trait Implementations§

§

impl<'a> Freeze for ParentState<'a>

§

impl<'a> RefUnwindSafe for ParentState<'a>

§

impl<'a> Send for ParentState<'a>

§

impl<'a> Sync for ParentState<'a>

§

impl<'a> Unpin for ParentState<'a>

§

impl<'a> !UnwindSafe for ParentState<'a>

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.