pub struct ObjectBuilder<'a> {
parent_state: ParentState<'a>,
fields: IndexMap<u32, usize>,
parent_value_offset_base: usize,
parent_metadata_offset_base: usize,
has_been_finished: bool,
validate_unique_fields: bool,
duplicate_fields: HashSet<u32>,
}
Expand description
A builder for creating Variant::Object
values.
See the examples on VariantBuilder
for usage.
Fields§
§parent_state: ParentState<'a>
§fields: IndexMap<u32, usize>
§parent_value_offset_base: usize
The starting offset in the parent’s buffer where this object starts
parent_metadata_offset_base: usize
The starting offset in the parent’s metadata buffer where this object starts
used to truncate the written fields in drop
if the current object has not been finished
has_been_finished: bool
Whether the object has been finished, the written content of the current object
will be truncated in drop
if has_been_finished
is false
validate_unique_fields: bool
§duplicate_fields: HashSet<u32>
Set of duplicate fields to report for errors
Implementations§
Source§impl<'a> ObjectBuilder<'a>
impl<'a> ObjectBuilder<'a>
fn new(parent_state: ParentState<'a>, validate_unique_fields: bool) -> Self
Sourcepub fn insert<'m, 'd, T: Into<Variant<'m, 'd>>>(&mut self, key: &str, value: T)
pub fn insert<'m, 'd, T: Into<Variant<'m, 'd>>>(&mut self, key: &str, value: T)
Add a field with key and value to the object
§See Also
ObjectBuilder::try_insert
for a fallible version.ObjectBuilder::with_field
for a builder-style API.
§Panics
This method will panic if the variant contains duplicate field names in objects
when validation is enabled. For a fallible version, use ObjectBuilder::try_insert
Sourcepub fn try_insert<'m, 'd, T: Into<Variant<'m, 'd>>>(
&mut self,
key: &str,
value: T,
) -> Result<(), ArrowError>
pub fn try_insert<'m, 'd, T: Into<Variant<'m, 'd>>>( &mut self, key: &str, value: T, ) -> Result<(), ArrowError>
Add a field with key and value to the object
§See Also
ObjectBuilder::insert
for a infallabel versionObjectBuilder::try_with_field
for a builder-style API.
§Note
When inserting duplicate keys, the new value overwrites the previous mapping, but the old value remains in the buffer, resulting in a larger variant
Sourcepub fn with_field<'m, 'd, T: Into<Variant<'m, 'd>>>(
self,
key: &str,
value: T,
) -> Self
pub fn with_field<'m, 'd, T: Into<Variant<'m, 'd>>>( self, key: &str, value: T, ) -> Self
Builder style API for adding a field with key and value to the object
Same as ObjectBuilder::insert
, but returns self
for chaining.
Sourcepub fn try_with_field<'m, 'd, T: Into<Variant<'m, 'd>>>(
self,
key: &str,
value: T,
) -> Result<Self, ArrowError>
pub fn try_with_field<'m, 'd, T: Into<Variant<'m, 'd>>>( self, key: &str, value: T, ) -> Result<Self, ArrowError>
Builder style API for adding a field with key and value to the object
Same as ObjectBuilder::try_insert
, but returns self
for chaining.
Sourcepub fn with_validate_unique_fields(self, validate_unique_fields: bool) -> Self
pub fn with_validate_unique_fields(self, validate_unique_fields: bool) -> Self
Enables validation for unique field keys when inserting into this object.
When this is enabled, calling ObjectBuilder::finish
will return an error
if any duplicate field keys were added using ObjectBuilder::insert
.
fn parent_state<'b>(&'b mut self, key: &'b str) -> (ParentState<'b>, bool)
Sourcepub fn new_object<'b>(&'b mut self, key: &'b str) -> ObjectBuilder<'b>
pub fn new_object<'b>(&'b mut self, key: &'b str) -> ObjectBuilder<'b>
Returns an object builder that can be used to append a new (nested) object to this object.
WARNING: The builder will have no effect unless/until ObjectBuilder::finish
is called.
Sourcepub fn new_list<'b>(&'b mut self, key: &'b str) -> ListBuilder<'b>
pub fn new_list<'b>(&'b mut self, key: &'b str) -> ListBuilder<'b>
Returns a list builder that can be used to append a new (nested) list to this object.
WARNING: The builder will have no effect unless/until ListBuilder::finish
is called.
Trait Implementations§
Source§impl Drop for ObjectBuilder<'_>
Drop implementation for ObjectBuilder does nothing
as the finish
method must be called to finalize the object.
This is to ensure that the object is always finalized before its parent builder
is finalized.
impl Drop for ObjectBuilder<'_>
Drop implementation for ObjectBuilder does nothing
as the finish
method must be called to finalize the object.
This is to ensure that the object is always finalized before its parent builder
is finalized.