Expand description
Core schema traits for compile-time Arrow typing.
This module provides the foundational traits generated by #[derive(Record)]:
§Schema Definition
| Trait | Description |
|---|---|
Record | Marker trait with const LEN: usize for column count |
ColAt<I> | Per-column metadata: type, name, nullability, builder, array |
ForEachCol | Compile-time iteration via ColumnVisitor |
SchemaMeta | Runtime schema: fields(), schema(), metadata() |
StructMeta | Nested struct support: child_fields(), new_struct_builder() |
§Row Building
| Trait | Description |
|---|---|
BuildRows | Entry point: new_builders(capacity) |
RowBuilder | Append methods: append_row(), append_rows(), finish() |
IntoRecordBatch | Convert arrays to RecordBatch |
AppendStruct | Append struct fields into a StructBuilder |
§Zero-Copy Views (requires views feature)
Read RecordBatch data without allocation using generated view types.
§Generated Types
For each #[derive(Record)] struct Foo, the macro generates:
FooView<'a>— Borrowed row view with fields as referencesFooViews<'a>— Iterator yieldingResult<FooView<'a>, ViewAccessError>impl TryFrom<FooView<'_>> for Foo— Convert view to owned record
§Reading Views
use typed_arrow::prelude::*;
#[derive(Record)]
struct Row {
id: i32,
name: String,
}
// Get iterator of views
for view in batch.iter_views::<Row>()?.try_flatten()? {
// view.id is i32 (copied), view.name is &str (zero-copy)
println!("{}: {}", view.id, view.name);
}§Converting Views to Owned
Use .try_into() when data must outlive the batch:
use typed_arrow::prelude::*;
#[derive(Record)]
struct Row {
id: i32,
name: String,
}
let mut owned_rows = Vec::new();
for view in batch.iter_views::<Row>()?.try_flatten()? {
let owned: Row = view.try_into()?; // Clone strings, copy primitives
owned_rows.push(owned);
}
// owned_rows can now outlive the batchThe conversion uses TryFrom with ViewAccessError to handle nested
structures that may fail during conversion.
§Key Traits
| Trait | Description |
|---|---|
FromRecordBatch | Create views from a batch via from_record_batch() |
ViewResultIteratorExt | Helper .try_flatten() for view iterators |
StructView | Internal: extract views from nested StructArray |
Re-exports§
pub use crate::error::SchemaError;pub use crate::error::ViewAccessError;
Structs§
- Field
Meta - Simple compile-time column metadata passed to visitors.
Traits§
- Append
Struct - Trait implemented by
#[derive(Record)]structs to append their fields into aStructBuilder. Used by row-based APIs to handle nested struct fields. - Append
Struct Ref - Trait implemented by
#[derive(Record)]structs to append their fields into aStructBuilderfrom a borrowed reference. This enables container builders (e.g., lists of structs) to append child values without taking ownership of the struct. - Build
Rows - Row-based building interface: construct typed column builders, append owned rows, and finish into typed arrays.
- ColAt
- Per-column metadata for a record at index
I. - Column
Visitor - A visitor invoked at compile time for each column of a
Record. - ForEach
Col - Trait emitted by derive/macro to enable
for_each_colexpansion. - From
Record Batch - Trait for creating zero-copy views over a RecordBatch.
- Into
Record Batch - Trait implemented by derive-generated arrays to assemble a
RecordBatch. - Record
- A record (row) with a fixed, compile-time number of columns.
- RowBuilder
- Trait implemented by derive-generated builders to append rows of
Rowand finish into a typed arrays struct. - Schema
Meta - Arrow runtime schema metadata for a top-level Record.
- Struct
Meta - Metadata and builder utilities for nested Struct fields.
- Struct
View - Trait for creating a view from a StructArray at a specific index.
- View
Result Iterator Ext - Extension trait providing convenience methods for iterators over
Result<T, ViewAccessError>.