ObjectBuilder

Struct ObjectBuilder 

Source
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>

Source

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.

Source

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
§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

Source

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
§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

Source

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

Source

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

Source

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.

Source

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.

Source

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.

Source

fn parent_state<'b>( &'b mut self, field_name: &'b str, ) -> Result<(ParentState<'b>, bool), ArrowError>

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn finish(self)

Finalizes this object and appends it to its parent, which otherwise remains unmodified.

Trait Implementations§

Source§

impl<'a> Debug for ObjectBuilder<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for ObjectBuilder<'a>

§

impl<'a> !RefUnwindSafe for ObjectBuilder<'a>

§

impl<'a> !Send for ObjectBuilder<'a>

§

impl<'a> !Sync for ObjectBuilder<'a>

§

impl<'a> Unpin for ObjectBuilder<'a>

§

impl<'a> !UnwindSafe for ObjectBuilder<'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.