Skip to main content

Module structs

Module structs 

Source
Expand description

StructArray — a column of named child columns, all the same length.

A struct array is a record batch that happens to be a column: n child arrays of equal length, plus one validity bitmap that nulls out a whole row across every child at once. AstRS uses it for compound payloads — Pose{position, orientation}, Detections{boxes, scores, labels} — where the fields must travel together.

A struct with no children carries no length information in its children, so StructArray::try_new needs an explicit one; that is what crate::DataError::UnknownStructLength reports.

use astrs_data::array::{Array, Float64Array, IntoArrayRef, StringArray, StructArray};
use astrs_data::{DataType, Field};

let pose = StructArray::try_new(
    vec![
        Field::new("frame", DataType::Utf8, false),
        Field::new("x", DataType::Float64, false),
    ],
    vec![
        StringArray::from_values(["odom", "map"]).into_array_ref(),
        Float64Array::from_values([1.0, 2.0]).into_array_ref(),
    ],
    None,
)?;

assert_eq!(pose.len(), 2);
assert_eq!(pose.num_columns(), 2);
assert!(pose.column_by_name("x").is_some());

Structs§

StructArray
A column of named child columns of equal length.