match_each_pvector

Macro match_each_pvector 

Source
macro_rules! match_each_pvector {
    ($self:expr, | $vec:ident | $body:block) => { ... };
}
Expand description

Matches on all primitive type variants of PrimitiveVector and executes the same code for each variant branch.

This macro eliminates repetitive match statements when implementing operations that need to work uniformly across all primitive type variants (U8, U16, U32, U64, I8, I16, I32, I64, F16, F32, F64).

ยงExamples

use vortex_vector::primitive::{PrimitiveVector, PVectorMut};
use vortex_vector::{VectorOps, VectorMutOps, match_each_pvector};

fn get_primitive_len(vector: &PrimitiveVector) -> usize {
    match_each_pvector!(vector, |v| { v.len() })
}

// Works with `I32` primitive vectors.
let i32_vec: PrimitiveVector = PVectorMut::<i32>::from_iter([1, 2, 3].map(Some))
    .freeze()
    .into();
assert_eq!(get_primitive_len(&i32_vec), 3);

// Works with `F64` primitive vectors.
let f64_vec: PrimitiveVector = PVectorMut::<f64>::from_iter([1.0, 2.5].map(Some))
    .freeze()
    .into();
assert_eq!(get_primitive_len(&f64_vec), 2);

Note: The len method is already provided by the VectorOps trait implementation.