match_each_pvector_mut

Macro match_each_pvector_mut 

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

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

This macro eliminates repetitive match statements when implementing mutable 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::{PrimitiveVectorMut, PVectorMut};
use vortex_vector::{VectorMutOps, match_each_pvector_mut};

fn reserve_primitive_space(vector: &mut PrimitiveVectorMut, additional: usize) {
    match_each_pvector_mut!(vector, |v| { v.reserve(additional) })
}

// Works with `U8` mutable primitive vectors.
let mut u8_vec: PrimitiveVectorMut = PVectorMut::<u8>::from_iter([1, 2].map(Some)).into();
reserve_primitive_space(&mut u8_vec, 10);
assert!(u8_vec.capacity() >= 12);

// Works with `I64` mutable primitive vectors.
let mut i64_vec: PrimitiveVectorMut = PVectorMut::<i64>::from_iter([100].map(Some)).into();
reserve_primitive_space(&mut i64_vec, 5);
assert!(i64_vec.capacity() >= 6);

Note: The reserve method is already provided by the VectorMutOps trait implementation.