polars_arrow/array/fixed_size_binary/
iterator.rs

1use super::{FixedSizeBinaryArray, MutableFixedSizeBinaryArray};
2use crate::array::MutableArray;
3use crate::bitmap::utils::{BitmapIter, ZipValidity};
4
5impl<'a> IntoIterator for &'a FixedSizeBinaryArray {
6    type Item = Option<&'a [u8]>;
7    type IntoIter = ZipValidity<&'a [u8], std::slice::ChunksExact<'a, u8>, BitmapIter<'a>>;
8
9    fn into_iter(self) -> Self::IntoIter {
10        self.iter()
11    }
12}
13
14impl<'a> FixedSizeBinaryArray {
15    /// constructs a new iterator
16    pub fn iter(
17        &'a self,
18    ) -> ZipValidity<&'a [u8], std::slice::ChunksExact<'a, u8>, BitmapIter<'a>> {
19        ZipValidity::new_with_validity(self.values_iter(), self.validity())
20    }
21
22    /// Returns iterator over the values of [`FixedSizeBinaryArray`]
23    pub fn values_iter(&'a self) -> std::slice::ChunksExact<'a, u8> {
24        self.values().chunks_exact(self.size)
25    }
26}
27
28impl<'a> IntoIterator for &'a MutableFixedSizeBinaryArray {
29    type Item = Option<&'a [u8]>;
30    type IntoIter = ZipValidity<&'a [u8], std::slice::ChunksExact<'a, u8>, BitmapIter<'a>>;
31
32    fn into_iter(self) -> Self::IntoIter {
33        self.iter()
34    }
35}
36
37impl<'a> MutableFixedSizeBinaryArray {
38    /// constructs a new iterator
39    pub fn iter(
40        &'a self,
41    ) -> ZipValidity<&'a [u8], std::slice::ChunksExact<'a, u8>, BitmapIter<'a>> {
42        ZipValidity::new(self.iter_values(), self.validity().map(|x| x.iter()))
43    }
44
45    /// Returns iterator over the values of [`MutableFixedSizeBinaryArray`]
46    pub fn iter_values(&'a self) -> std::slice::ChunksExact<'a, u8> {
47        self.values().chunks_exact(self.size())
48    }
49}