Path: blob/main/crates/polars-parquet/src/parquet/write/dyn_iter.rs
6940 views
use crate::parquet::FallibleStreamingIterator;12/// [`DynIter`] is an implementation of a single-threaded, dynamically-typed iterator.3///4/// This implementation is object safe.5pub struct DynIter<'a, V> {6iter: Box<dyn Iterator<Item = V> + 'a + Send + Sync>,7}89impl<V> Iterator for DynIter<'_, V> {10type Item = V;11fn next(&mut self) -> Option<Self::Item> {12self.iter.next()13}1415fn size_hint(&self) -> (usize, Option<usize>) {16self.iter.size_hint()17}18}1920impl<'a, V> DynIter<'a, V> {21/// Returns a new [`DynIter`], boxing the incoming iterator22pub fn new<I>(iter: I) -> Self23where24I: Iterator<Item = V> + 'a + Send + Sync,25{26Self {27iter: Box::new(iter),28}29}30}3132/// Dynamically-typed [`FallibleStreamingIterator`].33pub struct DynStreamingIterator<'a, V, E> {34iter: Box<dyn FallibleStreamingIterator<Item = V, Error = E> + 'a + Send + Sync>,35}3637impl<V, E> FallibleStreamingIterator for DynStreamingIterator<'_, V, E> {38type Item = V;39type Error = E;4041fn advance(&mut self) -> Result<(), Self::Error> {42self.iter.advance()43}4445fn get(&self) -> Option<&Self::Item> {46self.iter.get()47}4849fn size_hint(&self) -> (usize, Option<usize>) {50self.iter.size_hint()51}52}5354impl<'a, V, E> DynStreamingIterator<'a, V, E> {55/// Returns a new [`DynStreamingIterator`], boxing the incoming iterator56pub fn new<I>(iter: I) -> Self57where58I: FallibleStreamingIterator<Item = V, Error = E> + 'a + Send + Sync,59{60Self {61iter: Box::new(iter),62}63}64}656667