#[repr(C, align(64))]pub enum Array {
NumericArray(NumericArray),
TextArray(TextArray),
BooleanArray(Arc<BooleanArray<()>>),
Null,
}Expand description
§Array
Standard Array type. Wrap in a FieldArray when using inside a Table
or as a standalone value requiring tagged metadata.
§Overview
The dual-enum approach may look verbose but works well in practice:
- Enables clean function signatures with direct access to concrete types
(e.g.
&NumericArray), supporting trait-aligned dispatch without exhaustive matches at every call site. - Supports ergonomic categorisation: functions typically match on the outer enum for broad category handling (numeric, text, temporal, boolean), while allowing inner variant matching for precise type handling.
- The focused typeset (no nested types) helps keeps enum size efficient as memory is allocated for the largest variant.
§Usage
Functions can accept references tailored to the intended match granularity:
&IntegerArray: direct reference to the inner type e.g.,arr.num().i64().&NumericArray: any numeric type viaarr.num().&Array: match on categories or individual types.
§Benefits
- No heap allocation or runtime indirection - all enum variants are inline with minimal discriminant cost.
- Unified call sites with compiler-enforced type safety.
- Easy casting to inner types (e.g.,
.str()for strings). - Supports aggressive compiler inlining, unlike approaches relying on dynamic dispatch and downcasting.
§Trade-offs
- Adds ~30–100 ns latency compared to direct inner type calls - only noticeable in extreme low-latency contexts such as HFT.
- Requires enum matching at dispatch sites compared to direct inner type usage.
§Examples
use minarrow::{
Array, IntegerArray, NumericArray, arr_bool, arr_f64, arr_i32, arr_i64,
arr_str32, vec64
};
// Fast macro construction
let int_arr = arr_i32![1, 2, 3, 4];
let float_arr = arr_f64![0.5, 1.5, 2.5];
let bool_arr = arr_bool![true, false, true];
let str_arr = arr_str32!["a", "b", "c"];
assert_eq!(int_arr.len(), 4);
assert_eq!(str_arr.len(), 3);
// Manual construction
let int = IntegerArray::<i64>::from_slice(&[100, 200]);
let wrapped: NumericArray = NumericArray::Int64(std::sync::Arc::new(int));
let array = Array::NumericArray(wrapped);Variants§
Implementations§
Source§impl Array
impl Array
Sourcepub fn from_int32(arr: IntegerArray<i32>) -> Array
pub fn from_int32(arr: IntegerArray<i32>) -> Array
Creates an Array enum with an Int32 array.
Sourcepub fn from_int64(arr: IntegerArray<i64>) -> Array
pub fn from_int64(arr: IntegerArray<i64>) -> Array
Creates an Array enum with an Int64 array.
Sourcepub fn from_uint32(arr: IntegerArray<u32>) -> Array
pub fn from_uint32(arr: IntegerArray<u32>) -> Array
Creates an Array enum with a UInt32 array.
Sourcepub fn from_uint64(arr: IntegerArray<u64>) -> Array
pub fn from_uint64(arr: IntegerArray<u64>) -> Array
Creates an Array enum with an UInt64 array.
Sourcepub fn from_float32(arr: FloatArray<f32>) -> Array
pub fn from_float32(arr: FloatArray<f32>) -> Array
Creates an Array enum with a Float32 array.
Sourcepub fn from_float64(arr: FloatArray<f64>) -> Array
pub fn from_float64(arr: FloatArray<f64>) -> Array
Creates an Array enum with a Float64 array.
Sourcepub fn from_string32(arr: StringArray<u32>) -> Array
pub fn from_string32(arr: StringArray<u32>) -> Array
Creates an Array enum with a String32 array.
Sourcepub fn from_string64(arr: StringArray<u64>) -> Array
pub fn from_string64(arr: StringArray<u64>) -> Array
Creates an Array enum with a String64 array.
Sourcepub fn from_categorical8(arr: CategoricalArray<u8>) -> Array
pub fn from_categorical8(arr: CategoricalArray<u8>) -> Array
Creates an Array enum with a Categorical8 array.
Sourcepub fn from_bool(arr: BooleanArray<()>) -> Array
pub fn from_bool(arr: BooleanArray<()>) -> Array
Creates an Array enum with a Boolean array.
Sourcepub fn fa(self, name: impl Into<String>) -> FieldArray
pub fn fa(self, name: impl Into<String>) -> FieldArray
Wraps this Array in a FieldArray with the given name.
Infers the Arrow type and nullability from the array itself.
§Example
use minarrow::{Array, IntegerArray, MaskedArray};
let mut arr = IntegerArray::<i32>::default();
arr.push(1);
arr.push(2);
let array = Array::from_int32(arr);
let field_array = array.fa("my_column");
assert_eq!(field_array.field.name, "my_column");Sourcepub fn num_ref(&self) -> Result<&NumericArray, MinarrowError>
pub fn num_ref(&self) -> Result<&NumericArray, MinarrowError>
Returns a reference to the inner NumericArray if the variant matches.
No conversion or cloning is performed.
Sourcepub fn str_ref(&self) -> Result<&TextArray, MinarrowError>
pub fn str_ref(&self) -> Result<&TextArray, MinarrowError>
Returns a reference to the inner TextArray if the variant matches.
No conversion or cloning is performed.
Sourcepub fn bool_ref(&self) -> Result<&BooleanArray<()>, MinarrowError>
pub fn bool_ref(&self) -> Result<&BooleanArray<()>, MinarrowError>
Returns a reference to the inner BooleanArray if the variant matches.
No conversion or cloning is performed.
Sourcepub fn try_i32_ref(&self) -> Result<&IntegerArray<i32>, MinarrowError>
pub fn try_i32_ref(&self) -> Result<&IntegerArray<i32>, MinarrowError>
Returns a reference to the inner IntegerArray<i32>.
Sourcepub fn try_i64_ref(&self) -> Result<&IntegerArray<i64>, MinarrowError>
pub fn try_i64_ref(&self) -> Result<&IntegerArray<i64>, MinarrowError>
Returns a reference to the inner IntegerArray<i64>.
Sourcepub fn try_u32_ref(&self) -> Result<&IntegerArray<u32>, MinarrowError>
pub fn try_u32_ref(&self) -> Result<&IntegerArray<u32>, MinarrowError>
Returns a reference to the inner IntegerArray<u32>.
Sourcepub fn try_u64_ref(&self) -> Result<&IntegerArray<u64>, MinarrowError>
pub fn try_u64_ref(&self) -> Result<&IntegerArray<u64>, MinarrowError>
Returns a reference to the inner IntegerArray<u64>.
Sourcepub fn try_f32_ref(&self) -> Result<&FloatArray<f32>, MinarrowError>
pub fn try_f32_ref(&self) -> Result<&FloatArray<f32>, MinarrowError>
Returns a reference to the inner FloatArray<f32>.
Sourcepub fn try_f64_ref(&self) -> Result<&FloatArray<f64>, MinarrowError>
pub fn try_f64_ref(&self) -> Result<&FloatArray<f64>, MinarrowError>
Returns a reference to the inner FloatArray<f64>.
Sourcepub fn try_str32_ref(&self) -> Result<&StringArray<u32>, MinarrowError>
pub fn try_str32_ref(&self) -> Result<&StringArray<u32>, MinarrowError>
Returns a reference to the inner StringArray<u32>.
Sourcepub fn try_str64_ref(&self) -> Result<&StringArray<u64>, MinarrowError>
pub fn try_str64_ref(&self) -> Result<&StringArray<u64>, MinarrowError>
Returns a reference to the inner StringArray<u64>.
Sourcepub fn try_cat8_ref(&self) -> Result<&CategoricalArray<u8>, MinarrowError>
pub fn try_cat8_ref(&self) -> Result<&CategoricalArray<u8>, MinarrowError>
Returns a reference to the inner CategoricalArray<u8>.
Sourcepub fn num(self) -> NumericArray
pub fn num(self) -> NumericArray
Returns an inner NumericArray, consuming self.
- If already a
NumericArray, consumes and returns the inner value with no clone. - Other types: casts and copies.
Sourcepub fn str(self) -> TextArray
pub fn str(self) -> TextArray
Returns an inner TextArray, consuming self.
- If already a
TextArray, consumes and returns the inner value with no clone. - Other types: casts (to string) and copies.
Sourcepub fn bool(self) -> Arc<BooleanArray<()>>
pub fn bool(self) -> Arc<BooleanArray<()>>
Returns the inner BooleanArray, consuming self.
- If already a
BooleanArray, consumes and returns the inner value with no clone. - Other types: calculates the boolean mask based on whether the value is present, and non-zero,
and copies. In these cases, any null mask is preserved, rather than becoming
false.
Sourcepub fn view(&self, offset: usize, len: usize) -> ArrayV
pub fn view(&self, offset: usize, len: usize) -> ArrayV
Returns a metadata view and reference over the specified window of this array.
Does not slice the object (yet).
Panics if out of bounds.
Sourcepub fn view_tuple(&self, offset: usize, len: usize) -> (&Array, usize, usize)
pub fn view_tuple(&self, offset: usize, len: usize) -> (&Array, usize, usize)
Returns a metadata view and reference over the specified window of this array.
Does not slice the object (yet).
Panics if out of bounds.
Sourcepub fn inner<T>(&self) -> &Arc<T>where
T: 'static,
pub fn inner<T>(&self) -> &Arc<T>where
T: 'static,
Returns a reference to the inner array as type Arc<T>.
This is compile-time safe if T matches the actual payload, but will panic otherwise.
Prefer .inner_check() for Option-based pattern.
Sourcepub fn inner_mut<T>(&mut self) -> &mut Arc<T>where
T: 'static,
pub fn inner_mut<T>(&mut self) -> &mut Arc<T>where
T: 'static,
Returns a mutable reference to the inner array as type T.
This method is compile-time safe when the type T matches the actual inner type,
but relies on TypeId checks and unsafe casting. If an incorrect type is specified,
this will panic at runtime.
Prefer inner_check_mut if you want an Option-based version that avoids panics.
Sourcepub fn inner_check<T>(&self) -> Option<&Arc<T>>where
T: 'static,
pub fn inner_check<T>(&self) -> Option<&Arc<T>>where
T: 'static,
Returns a reference to the inner array as type T, if the type matches.
This method performs a runtime TypeId check to verify that the provided type T
corresponds to the actual inner variant. If the types match, returns Some(&T);
otherwise, returns None without panicking.
Use when the type of the variant is uncertain at compile time.
Sourcepub fn inner_check_mut<T>(&mut self) -> Option<&mut Arc<T>>where
T: 'static,
pub fn inner_check_mut<T>(&mut self) -> Option<&mut Arc<T>>where
T: 'static,
Returns a mutable reference to the inner array as type T, if the type matches.
This method performs a runtime TypeId check to verify that the provided type T
corresponds to the actual inner variant. If the types match, returns Some(&mut T);
otherwise, returns None without panicking.
Use when the type of the variant is uncertain at compile time.
pub fn as_slice<T>(&self, offset: usize, len: usize) -> &[T]
pub fn slice_raw<T>(&self, offset: usize, len: usize) -> Option<&[T]>where
T: 'static,
Sourcepub fn slice_clone(&self, offset: usize, len: usize) -> Array
pub fn slice_clone(&self, offset: usize, len: usize) -> Array
Returns a new Array of the same variant sliced to the given offset and length
.
Copies the data of the scoped range that’s selected.
If out-of-bounds, returns Self::Null. All null mask, offsets, etc. are trimmed.
Sourcepub fn arrow_type(&self) -> ArrowType
pub fn arrow_type(&self) -> ArrowType
Arrow physical type for this array.
Sourcepub fn is_nullable(&self) -> bool
pub fn is_nullable(&self) -> bool
Column nullability
Sourcepub fn is_categorical_array(&self) -> bool
pub fn is_categorical_array(&self) -> bool
Returns true if this is a categorical array.
Sourcepub fn is_string_array(&self) -> bool
pub fn is_string_array(&self) -> bool
Returns true if this is a string array i.e. non-categorical text.
Sourcepub fn is_text_array(&self) -> bool
pub fn is_text_array(&self) -> bool
Returns true if this is any text array, string or categorical.
Sourcepub fn is_boolean_array(&self) -> bool
pub fn is_boolean_array(&self) -> bool
Returns true if this is a boolean array.
Sourcepub fn is_integer_array(&self) -> bool
pub fn is_integer_array(&self) -> bool
Returns true if this is an integer array.
Sourcepub fn is_float_array(&self) -> bool
pub fn is_float_array(&self) -> bool
Returns true if this is a floating-point array.
Sourcepub fn is_numerical_array(&self) -> bool
pub fn is_numerical_array(&self) -> bool
Returns true if this is any numeric array, integer or float.
Sourcepub fn value_to_string(&self, idx: usize) -> String
pub fn value_to_string(&self, idx: usize) -> String
Format the element at idx as a human-readable string.
Returns "null" for null elements. Uses the same formatting as
the array’s Display implementation.
Sourcepub fn null_array(arrow_type: &ArrowType, n_rows: usize) -> Array
pub fn null_array(arrow_type: &ArrowType, n_rows: usize) -> Array
Create an all-null array of the given ArrowType with n_rows elements.
The data buffer is zero-filled and every element is masked as null. For datetime types, set the time_unit on the returned array afterwards.
Sourcepub fn compare_at(&self, i: usize, j: usize) -> Ordering
pub fn compare_at(&self, i: usize, j: usize) -> Ordering
Compare two elements within the same array by index.
Uses total ordering for floats via total_cmp(). Nulls sort last:
null > any value, null == null.
Sourcepub fn set_null_mask(&mut self, mask: Bitmask)
pub fn set_null_mask(&mut self, mask: Bitmask)
Set null mask on Array by matching on variants
Sourcepub fn data_ptr_and_byte_len(&self) -> (*const u8, usize, usize)
pub fn data_ptr_and_byte_len(&self) -> (*const u8, usize, usize)
Returns a pointer to the backing data (contiguous bytes), length in elements, and element size.
This is not logical length - it is total raw bytes in the buffer, so for non-fixed width types such as bit-packed booleans or strings, please factor this in accordingly.
Sourcepub fn null_mask_ptr_and_byte_len(&self) -> Option<(*const u8, usize)>
pub fn null_mask_ptr_and_byte_len(&self) -> Option<(*const u8, usize)>
Returns a pointer to the null mask and its length in bytes, if present.
Sourcepub fn offsets_ptr_and_len(&self) -> Option<(*const u8, usize)>
pub fn offsets_ptr_and_len(&self) -> Option<(*const u8, usize)>
Offsets pointer/len for variable-length types
Sourcepub fn null_count(&self) -> usize
pub fn null_count(&self) -> usize
Returns the null count of the array
Sourcepub fn concat_array(&mut self, other: &Array)
pub fn concat_array(&mut self, other: &Array)
Appends all values (and null mask if present) from other into self.
Panics if the two arrays are of different variants or incompatible types.
This function uses copy-on-write semantics for arrays wrapped in Arc.
If self is the only owner of its data, appends are performed in place without copying the first array.
If the array data is shared (Arc reference count > 1), the data is first cloned
(so the mutation does not affect other owners), and the append is then performed on the unique copy.
The second array is allocated into the buffer, which is standard.
Sourcepub fn concat_array_range(
&mut self,
other: &Array,
offset: usize,
len: usize,
) -> Result<(), MinarrowError>
pub fn concat_array_range( &mut self, other: &Array, offset: usize, len: usize, ) -> Result<(), MinarrowError>
Appends rows [offset..offset+len) from another array into self.
Extends data and null masks directly from the source range.
Sourcepub fn insert_rows(
&mut self,
index: usize,
other: &Array,
) -> Result<(), MinarrowError>
pub fn insert_rows( &mut self, index: usize, other: &Array, ) -> Result<(), MinarrowError>
Inserts all values (and null mask if present) from other into self at the specified index.
This is an O(n) operation.
Returns an error if the two arrays are of different variants or incompatible types, or if the index is out of bounds.
Sourcepub fn split(
self,
index: usize,
field: &Arc<Field>,
) -> Result<SuperArray, MinarrowError>
pub fn split( self, index: usize, field: &Arc<Field>, ) -> Result<SuperArray, MinarrowError>
Splits the Array at the specified index, consuming self and returning a SuperArray with two FieldArray chunks.
Splits the underlying buffers (via vec .split_off()), allocating new storage for the second half.
More efficient than cloning the entire array but requires allocation.
Trait Implementations§
Source§impl Concatenate for Array
impl Concatenate for Array
Source§impl From<Arc<CategoricalArray<u8>>> for Array
Available on crate feature default_categorical_8 only.
impl From<Arc<CategoricalArray<u8>>> for Array
default_categorical_8 only.Source§impl From<Array> for SuperArray
impl From<Array> for SuperArray
Source§fn from(array: Array) -> SuperArray
fn from(array: Array) -> SuperArray
Source§impl From<Array> for BooleanArrayV
impl From<Array> for BooleanArrayV
Source§fn from(array: Array) -> BooleanArrayV
fn from(array: Array) -> BooleanArrayV
Source§impl From<Array> for NumericArrayV
impl From<Array> for NumericArrayV
Source§fn from(array: Array) -> NumericArrayV
fn from(array: Array) -> NumericArrayV
Source§impl From<Array> for TextArrayV
impl From<Array> for TextArrayV
Source§fn from(array: Array) -> TextArrayV
fn from(array: Array) -> TextArrayV
Source§impl From<CategoricalArray<u8>> for Array
Available on crate feature default_categorical_8 only.
impl From<CategoricalArray<u8>> for Array
default_categorical_8 only.Source§impl FromIterator<Array> for SuperArray
impl FromIterator<Array> for SuperArray
Source§fn from_iter<T>(iter: T) -> SuperArraywhere
T: IntoIterator<Item = Array>,
fn from_iter<T>(iter: T) -> SuperArraywhere
T: IntoIterator<Item = Array>,
Source§impl RowSelection for Array
Available on crate features select and views only.
impl RowSelection for Array
select and views only.Source§fn r<S>(&self, selection: S) -> ArrayVwhere
S: DataSelector,
fn r<S>(&self, selection: S) -> ArrayVwhere
S: DataSelector,
Select rows by index or range, returning an ArrayV (view)
For contiguous selections (ranges), creates a zero-copy view. For non-contiguous selections (index arrays), gathers into a new array.