diff --git a/arrow_convert/src/features/glam.rs b/arrow_convert/src/features/glam.rs index 93445c3..9ff190f 100644 --- a/arrow_convert/src/features/glam.rs +++ b/arrow_convert/src/features/glam.rs @@ -12,6 +12,16 @@ use arrow::array::{BooleanBuilder, Float32Builder, Float64Builder}; use arrow::array::{FixedSizeListArray, FixedSizeListBuilder}; use std::sync::Arc; +/// This macro implements the `ArrowSerialize` and `ArrowDeserialize` traits for a given `glam` vector or matrix type. +/// +/// The macro takes the following parameters: +/// - `$type`: The type of the `glam` vector or matrix to implement the traits for. +/// - `$size`: The size of the vector or matrix (e.g. 2 for `glam::Vec2`, 4 for `glam::Mat4`). +/// - `$dt`: The data type of the elements in the vector or matrix (e.g. `bool`, `f32`). +/// - `$arrow_dt`: The corresponding Arrow data type for the element type. +/// - `$array_builder`: The Arrow array builder type to use for the element type. +/// - `$se`: A closure that serializes the `$type` to a slice of the element type. +/// - `$de`: A closure that deserializes a `Vec` of the element type to the `$type`. macro_rules! impl_glam_ty { ($type:ty, $size:expr, $dt:ident, $arrow_dt:expr, $array_builder:ident, $se:expr, $de:expr) => { impl ArrowField for $type { @@ -53,6 +63,7 @@ macro_rules! impl_glam_ty { }; } +/// Implements the `ArrowSerialize` and `ArrowDeserialize` traits for the given `glam::Vec` type. macro_rules! impl_glam_vec_bool { ($type:ty, $size:expr) => { impl_glam_ty!( @@ -79,6 +90,7 @@ macro_rules! impl_glam_vec_bool { }; } +/// Implements the `ArrowSerialize` and `ArrowDeserialize` traits for the given `glam::Vec2` type. macro_rules! impl_glam_vec_f32 { ($type:ty, $size:expr) => { impl_glam_ty!( @@ -93,6 +105,7 @@ macro_rules! impl_glam_vec_f32 { }; } +/// Implements the `ArrowSerialize` and `ArrowDeserialize` traits for the given `glam::Mat2`, `glam::Mat3`, and `glam::Mat4` types. macro_rules! impl_glam_mat_f32 { ($type:ty, $size:expr) => { impl_glam_ty!( @@ -107,6 +120,7 @@ macro_rules! impl_glam_mat_f32 { }; } +/// Implements the `ArrowSerialize` and `ArrowDeserialize` traits for the given `glam::DVec2`, `glam::DVec3`, and `glam::DVec4` types. macro_rules! impl_glam_vec_f64 { ($type:ty, $size:expr) => { impl_glam_ty!( @@ -121,6 +135,7 @@ macro_rules! impl_glam_vec_f64 { }; } +/// Implements the `ArrowSerialize` and `ArrowDeserialize` traits for the given `glam::DMat2`, `glam::DMat3`, and `glam::DMat4` types. macro_rules! impl_glam_mat_f64 { ($type:ty, $size:expr) => { impl_glam_ty!( diff --git a/arrow_convert/tests/test_tinystr.rs b/arrow_convert/tests/test_tinystr.rs index a552b3b..0e072f7 100644 --- a/arrow_convert/tests/test_tinystr.rs +++ b/arrow_convert/tests/test_tinystr.rs @@ -26,3 +26,24 @@ fn test_tinyasciistr_roundtrip() { // Verify the roundtrip assert_eq!(original, roundtrip); } + +#[cfg(feature = "tinystr")] +#[test] +fn test_tinyasciistr_max_length() { + use arrow::array::{Array, ArrayRef, FixedSizeBinaryArray}; + use arrow_convert::deserialize::TryIntoCollection; + use arrow_convert::serialize::TryIntoArrow; + use tinystr::TinyAsciiStr; + + let original: Vec> = vec![TinyAsciiStr::from_str("ABCDEFGHIJ").unwrap()]; + + let arrow_array: ArrayRef = original.try_into_arrow().expect("Failed to convert to Arrow array"); + assert!(arrow_array.as_any().is::()); + let fixed_size_array = arrow_array.as_any().downcast_ref::().unwrap(); + assert_eq!(fixed_size_array.value_length(), 10); + + let roundtrip: Vec> = arrow_array + .try_into_collection() + .expect("Failed to convert from Arrow array"); + assert_eq!(original, roundtrip); +}