Struct ParentState
pub struct ParentState<'a, S>where
S: BuilderSpecificState,{
pub(crate) value_builder: &'a mut ValueBuilder,
pub(crate) saved_value_builder_offset: usize,
pub(crate) metadata_builder: &'a mut dyn MetadataBuilder,
pub(crate) saved_metadata_builder_dict_size: usize,
pub(crate) builder_state: S,
pub(crate) 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: boolImplementations§
§impl<'a> ParentState<'a, ListState<'a>>
impl<'a> ParentState<'a, ListState<'a>>
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,
) -> ParentState<'a, ListState<'a>>
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, ) -> ParentState<'a, ListState<'a>>
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.
§impl<'a> ParentState<'a, ObjectState<'a>>
impl<'a> ParentState<'a, ObjectState<'a>>
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<ParentState<'a, ObjectState<'a>>, ArrowError>
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<ParentState<'a, ObjectState<'a>>, 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).
§impl<'a, S> ParentState<'a, S>where
S: BuilderSpecificState,
impl<'a, S> ParentState<'a, S>where
S: BuilderSpecificState,
pub fn new(
value_builder: &'a mut ValueBuilder,
metadata_builder: &'a mut dyn MetadataBuilder,
builder_state: S,
) -> ParentState<'a, S>
pub fn new( value_builder: &'a mut ValueBuilder, metadata_builder: &'a mut dyn MetadataBuilder, builder_state: S, ) -> ParentState<'a, S>
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.
pub fn finish(&mut self)
pub fn finish(&mut self)
Marks the insertion as having succeeded and invokes
BuilderSpecificState::finish. Internal state will no longer roll back on drop.
§impl<'a> ParentState<'a, ()>
impl<'a> ParentState<'a, ()>
pub fn variant(
value_builder: &'a mut ValueBuilder,
metadata_builder: &'a mut dyn MetadataBuilder,
) -> ParentState<'a, ()>
pub fn variant( value_builder: &'a mut ValueBuilder, metadata_builder: &'a mut dyn MetadataBuilder, ) -> ParentState<'a, ()>
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.
Trait Implementations§
§impl<'a, S> Debug for ParentState<'a, S>where
S: Debug + BuilderSpecificState,
impl<'a, S> Debug for ParentState<'a, S>where
S: Debug + BuilderSpecificState,
§impl<S> Drop for ParentState<'_, S>where
S: BuilderSpecificState,
Automatically rolls back any unfinished ParentState.
impl<S> Drop for ParentState<'_, S>where
S: BuilderSpecificState,
Automatically rolls back any unfinished ParentState.
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more