ParentState

Struct ParentState 

Source
pub struct ParentState<'a, S: BuilderSpecificState> {
    value_builder: &'a mut ValueBuilder,
    saved_value_builder_offset: usize,
    metadata_builder: &'a mut dyn MetadataBuilder,
    saved_metadata_builder_dict_size: usize,
    builder_state: S,
    finished: bool,
}
Expand description

Tracks information needed to correctly finalize a nested builder.

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

Fields§

§value_builder: &'a mut ValueBuilder§saved_value_builder_offset: usize§metadata_builder: &'a mut dyn MetadataBuilder§saved_metadata_builder_dict_size: usize§builder_state: S§finished: bool

Implementations§

Source§

impl<'a, S: BuilderSpecificState> ParentState<'a, S>

Source

pub fn new( value_builder: &'a mut ValueBuilder, metadata_builder: &'a mut dyn MetadataBuilder, builder_state: S, ) -> Self

Creates a new ParentState instance. The value and metadata builder state is checkpointed and will roll back on drop, unless Self::finish is called. The builder-specific state is governed by its own finish and rollback calls.

Source

pub fn finish(&mut self)

Marks the insertion as having succeeded and invokes BuilderSpecificState::finish. Internal state will no longer roll back on drop.

Source

fn rollback(&mut self)

Source

fn value_builder(&mut self) -> &mut ValueBuilder

Source

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

Source§

impl<'a> ParentState<'a, ()>

Source

pub fn variant( value_builder: &'a mut ValueBuilder, metadata_builder: &'a mut dyn MetadataBuilder, ) -> Self

Creates a new instance suitable for a top-level variant builder (e.g. VariantBuilder). The value and metadata builder state is checkpointed and will roll back on drop, unless Self::finish is called.

Source§

impl<'a> ParentState<'a, ListState<'a>>

Source

pub fn list( value_builder: &'a mut ValueBuilder, metadata_builder: &'a mut dyn MetadataBuilder, offsets: &'a mut Vec<usize>, saved_parent_value_builder_offset: usize, ) -> Self

Creates a new instance suitable for a ListBuilder. The value and metadata builder state is checkpointed and will roll back on drop, unless Self::finish is called. The new element’s offset is also captured eagerly and will also roll back if not finished.

Source§

impl<'a> ParentState<'a, ObjectState<'a>>

Source

pub fn try_object( value_builder: &'a mut ValueBuilder, metadata_builder: &'a mut dyn MetadataBuilder, fields: &'a mut IndexMap<u32, usize>, saved_parent_value_builder_offset: usize, field_name: &str, validate_unique_fields: bool, ) -> Result<Self, ArrowError>

Creates a new instance suitable for an ObjectBuilder. The value and metadata builder state is checkpointed and will roll back on drop, unless Self::finish is called. The new field’s name and offset are also captured eagerly and will also roll back if not finished.

The call fails if the field name is invalid (e.g. because it duplicates an existing field).

Trait Implementations§

Source§

impl<'a, S: Debug + BuilderSpecificState> Debug for ParentState<'a, S>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<S: BuilderSpecificState> Drop for ParentState<'_, S>

Automatically rolls back any unfinished ParentState.

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a, S> Freeze for ParentState<'a, S>
where S: Freeze,

§

impl<'a, S> !RefUnwindSafe for ParentState<'a, S>

§

impl<'a, S> !Send for ParentState<'a, S>

§

impl<'a, S> !Sync for ParentState<'a, S>

§

impl<'a, S> Unpin for ParentState<'a, S>
where S: Unpin,

§

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

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.