pub struct ObjectBuilder<'a> {
parent_state: ParentState<'a>,
fields: IndexMap<u32, usize>,
validate_unique_fields: bool,
}
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>
§validate_unique_fields: bool
Implementations§
Source§impl<'a> ObjectBuilder<'a>
impl<'a> ObjectBuilder<'a>
Sourcepub fn new(parent_state: ParentState<'a>, validate_unique_fields: bool) -> Self
pub fn new(parent_state: ParentState<'a>, validate_unique_fields: bool) -> Self
Creates a new object builder, nested on top of the given parent state.
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 an infallible version that panicsObjectBuilder::try_with_field
for a builder-style API.
§Note
Attempting to insert a duplicate field name produces an error if unique field validation is enabled. Otherwise, the new value overwrites the previous field mapping without erasing the old value, resulting in a larger variant
Sourcepub fn insert_bytes<'m, 'd>(
&mut self,
key: &str,
value: impl Into<Variant<'m, 'd>>,
)
pub fn insert_bytes<'m, 'd>( &mut self, key: &str, value: impl Into<Variant<'m, 'd>>, )
Add a field with key and value to the object by copying raw bytes when possible.
For objects and lists, this directly copies their underlying byte representation instead of performing a logical copy, and without touching the metadata builder. For other variant types, this falls back to the standard append behavior.
The caller must ensure that the metadata dictionary is already built and correct for any objects or lists being appended, but the value’s new field name is handled normally.
§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_bytes
Sourcepub fn try_insert_bytes<'m, 'd>(
&mut self,
key: &str,
value: impl Into<Variant<'m, 'd>>,
) -> Result<(), ArrowError>
pub fn try_insert_bytes<'m, 'd>( &mut self, key: &str, value: impl Into<Variant<'m, 'd>>, ) -> Result<(), ArrowError>
Add a field with key and value to the object by copying raw bytes when possible.
For objects and lists, this directly copies their underlying byte representation instead of performing a logical copy, and without touching the metadata builder. For other variant types, this falls back to the standard append behavior.
The caller must ensure that the metadata dictionary is already built and correct for any objects or lists being appended, but the value’s new field name is handled normally.
§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, field_name: &'b str, ) -> Result<(ParentState<'b>, bool), ArrowError>
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.
Panics if the proposed key was a duplicate
WARNING: The builder will have no effect unless/until ObjectBuilder::finish
is called.
Sourcepub fn try_new_object<'b>(
&'b mut self,
key: &'b str,
) -> Result<ObjectBuilder<'b>, ArrowError>
pub fn try_new_object<'b>( &'b mut self, key: &'b str, ) -> Result<ObjectBuilder<'b>, ArrowError>
Returns an object builder that can be used to append a new (nested) object to this object.
Fails if the proposed key was a duplicate
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.
Panics if the proposed key was a duplicate
WARNING: The builder will have no effect unless/until ListBuilder::finish
is called.
Sourcepub fn try_new_list<'b>(
&'b mut self,
key: &'b str,
) -> Result<ListBuilder<'b>, ArrowError>
pub fn try_new_list<'b>( &'b mut self, key: &'b str, ) -> Result<ListBuilder<'b>, ArrowError>
Returns a list builder that can be used to append a new (nested) list to this object.
Fails if the proposed key was a duplicate
WARNING: The builder will have no effect unless/until ListBuilder::finish
is called.