Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-parquet/src/parquet/write/dyn_iter.rs
6940 views
1
use crate::parquet::FallibleStreamingIterator;
2
3
/// [`DynIter`] is an implementation of a single-threaded, dynamically-typed iterator.
4
///
5
/// This implementation is object safe.
6
pub struct DynIter<'a, V> {
7
iter: Box<dyn Iterator<Item = V> + 'a + Send + Sync>,
8
}
9
10
impl<V> Iterator for DynIter<'_, V> {
11
type Item = V;
12
fn next(&mut self) -> Option<Self::Item> {
13
self.iter.next()
14
}
15
16
fn size_hint(&self) -> (usize, Option<usize>) {
17
self.iter.size_hint()
18
}
19
}
20
21
impl<'a, V> DynIter<'a, V> {
22
/// Returns a new [`DynIter`], boxing the incoming iterator
23
pub fn new<I>(iter: I) -> Self
24
where
25
I: Iterator<Item = V> + 'a + Send + Sync,
26
{
27
Self {
28
iter: Box::new(iter),
29
}
30
}
31
}
32
33
/// Dynamically-typed [`FallibleStreamingIterator`].
34
pub struct DynStreamingIterator<'a, V, E> {
35
iter: Box<dyn FallibleStreamingIterator<Item = V, Error = E> + 'a + Send + Sync>,
36
}
37
38
impl<V, E> FallibleStreamingIterator for DynStreamingIterator<'_, V, E> {
39
type Item = V;
40
type Error = E;
41
42
fn advance(&mut self) -> Result<(), Self::Error> {
43
self.iter.advance()
44
}
45
46
fn get(&self) -> Option<&Self::Item> {
47
self.iter.get()
48
}
49
50
fn size_hint(&self) -> (usize, Option<usize>) {
51
self.iter.size_hint()
52
}
53
}
54
55
impl<'a, V, E> DynStreamingIterator<'a, V, E> {
56
/// Returns a new [`DynStreamingIterator`], boxing the incoming iterator
57
pub fn new<I>(iter: I) -> Self
58
where
59
I: FallibleStreamingIterator<Item = V, Error = E> + 'a + Send + Sync,
60
{
61
Self {
62
iter: Box::new(iter),
63
}
64
}
65
}
66
67