vortex_array/arrays/primitive/array/
accessor.rs1use std::iter;
5
6use vortex_error::VortexExpect;
7
8#[expect(deprecated)]
9use crate::ToCanonical as _;
10use crate::accessor::ArrayAccessor;
11use crate::arrays::PrimitiveArray;
12use crate::dtype::NativePType;
13use crate::validity::Validity;
14
15impl<T: NativePType> ArrayAccessor<T> for PrimitiveArray {
16 fn with_iterator<F, R>(&self, f: F) -> R
17 where
18 F: for<'a> FnOnce(&mut dyn Iterator<Item = Option<&'a T>>) -> R,
19 {
20 match self
21 .validity()
22 .vortex_expect("primitive validity should be derivable")
23 {
24 Validity::NonNullable | Validity::AllValid => {
25 let mut iter = self.as_slice::<T>().iter().map(Some);
26 f(&mut iter)
27 }
28 Validity::AllInvalid => f(&mut iter::repeat_n(None, self.len())),
29 Validity::Array(v) => {
30 #[expect(deprecated)]
31 let validity = v.to_bool().into_bit_buffer();
32 let mut iter = self
33 .as_slice::<T>()
34 .iter()
35 .zip(validity.iter())
36 .map(|(value, valid)| valid.then_some(value));
37 f(&mut iter)
38 }
39 }
40 }
41}