pub trait ArrayBuilder:
Send
+ Sync
+ Sized
+ 'static {
type ArrayType: Array<Builder = Self>;
// Required methods
fn new(capacity: usize) -> Self;
fn with_type(capacity: usize, ty: DataType) -> Self;
fn append_n(
&mut self,
n: usize,
value: Option<<Self::ArrayType as Array>::RefItem<'_>>,
);
fn append_array(&mut self, other: &Self::ArrayType);
fn pop(&mut self) -> Option<()>;
fn len(&self) -> usize;
fn finish(self) -> Self::ArrayType;
// Provided methods
fn append(&mut self, value: Option<<Self::ArrayType as Array>::RefItem<'_>>) { ... }
fn append_owned(
&mut self,
value: Option<<Self::ArrayType as Array>::OwnedItem>,
) { ... }
fn append_null(&mut self) { ... }
fn append_array_element(&mut self, other: &Self::ArrayType, idx: usize) { ... }
fn is_empty(&self) -> bool { ... }
}
Expand description
A trait over all array builders.
ArrayBuilder
is a trait over all builders. You could build an array with
append
with the help of ArrayBuilder
trait. The append
function always
accepts reference to an element if it is not primitive. e.g. for PrimitiveArray
,
you could do builder.append(Some(1))
. For Utf8Array
, you must do
builder.append(Some("xxx"))
. Note that you don’t need to construct a String
.
The associated type ArrayType
is the type of the corresponding array. It is the
return type of finish
.
Required Associated Types§
Required Methods§
sourcefn new(capacity: usize) -> Self
fn new(capacity: usize) -> Self
Create a new builder with capacity
.
TODO: remove this function from the trait. Let it be methods of each concrete builders.
sourcefn with_type(capacity: usize, ty: DataType) -> Self
fn with_type(capacity: usize, ty: DataType) -> Self
§Panics
Panics if meta
’s type mismatches with the array type.
sourcefn append_n(
&mut self,
n: usize,
value: Option<<Self::ArrayType as Array>::RefItem<'_>>,
)
fn append_n( &mut self, n: usize, value: Option<<Self::ArrayType as Array>::RefItem<'_>>, )
Append a value multiple times.
This should be more efficient than calling append
multiple times.
sourcefn append_array(&mut self, other: &Self::ArrayType)
fn append_array(&mut self, other: &Self::ArrayType)
Append an array to builder.
Provided Methods§
sourcefn append(&mut self, value: Option<<Self::ArrayType as Array>::RefItem<'_>>)
fn append(&mut self, value: Option<<Self::ArrayType as Array>::RefItem<'_>>)
Append a value to builder.
sourcefn append_owned(&mut self, value: Option<<Self::ArrayType as Array>::OwnedItem>)
fn append_owned(&mut self, value: Option<<Self::ArrayType as Array>::OwnedItem>)
Append an owned value to builder.
fn append_null(&mut self)
sourcefn append_array_element(&mut self, other: &Self::ArrayType, idx: usize)
fn append_array_element(&mut self, other: &Self::ArrayType, idx: usize)
Append an element in another array into builder.