macro_rules! match_each_vector {
($self:expr, | $vec:ident | $body:block) => { ... };
}Expand description
Matches on all variants of Vector 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 vector type variants.
ยงExamples
use vortex_vector::Vector;
use vortex_vector::bool::BoolVectorMut;
use vortex_vector::null::NullVector;
use vortex_vector::{VectorOps, VectorMutOps, match_each_vector};
fn get_vector_length(vector: &Vector) -> usize {
match_each_vector!(vector, |v| { v.len() })
}
// Works with `Null` vectors.
let null_vec: Vector = NullVector::new(5).into();
assert_eq!(get_vector_length(&null_vec), 5);
// Works with `Bool` vectors.
let bool_vec: Vector = BoolVectorMut::from_iter([true, false, true].map(Some))
.freeze()
.into();
assert_eq!(get_vector_length(&bool_vec), 3);Note: The len method is already provided by the VectorOps trait implementation.