papergrid/records/
iter_records.rs1use super::{IntoRecords, Records};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
5pub struct IterRecords<I> {
6 iter: I,
7 count_columns: usize,
8 count_rows: Option<usize>,
9}
10
11impl<I> IterRecords<I> {
12 pub const fn new(iter: I, count_columns: usize, count_rows: Option<usize>) -> Self {
14 Self {
15 iter,
16 count_columns,
17 count_rows,
18 }
19 }
20}
21
22impl<I> IntoRecords for IterRecords<I>
23where
24 I: IntoRecords,
25{
26 type Cell = I::Cell;
27 type IterColumns = I::IterColumns;
28 type IterRows = I::IterRows;
29
30 fn iter_rows(self) -> Self::IterRows {
31 self.iter.iter_rows()
32 }
33}
34
35impl<I> Records for IterRecords<I>
36where
37 I: IntoRecords,
38{
39 type Iter = I;
40
41 fn iter_rows(self) -> <Self::Iter as IntoRecords>::IterRows {
42 self.iter.iter_rows()
43 }
44
45 fn count_columns(&self) -> usize {
46 self.count_columns
47 }
48
49 fn hint_count_rows(&self) -> Option<usize> {
50 self.count_rows
51 }
52}
53
54impl<'a, I> Records for &'a IterRecords<I>
55where
56 &'a I: IntoRecords,
57{
58 type Iter = &'a I;
59
60 fn iter_rows(self) -> <Self::Iter as IntoRecords>::IterRows {
61 (&self.iter).iter_rows()
62 }
63
64 fn count_columns(&self) -> usize {
65 self.count_columns
66 }
67
68 fn hint_count_rows(&self) -> Option<usize> {
69 self.count_rows
70 }
71}