1 | //! An empty [`Records`] implementation. |
2 | |
3 | use core::iter::{repeat, Repeat, Take}; |
4 | |
5 | use super::Records; |
6 | |
7 | /// Empty representation of [`Records`]. |
8 | #[derive (Debug, Default, Clone)] |
9 | pub struct EmptyRecords { |
10 | rows: usize, |
11 | cols: usize, |
12 | } |
13 | |
14 | impl EmptyRecords { |
15 | /// Constructs an empty representation of [`Records`] with a given shape. |
16 | pub fn new(rows: usize, cols: usize) -> Self { |
17 | Self { rows, cols } |
18 | } |
19 | } |
20 | |
21 | impl From<(usize, usize)> for EmptyRecords { |
22 | fn from((count_rows: usize, count_columns: usize): (usize, usize)) -> Self { |
23 | Self::new(count_rows, cols:count_columns) |
24 | } |
25 | } |
26 | |
27 | impl Records for EmptyRecords { |
28 | type Iter = Take<Repeat<Take<Repeat<&'static str>>>>; |
29 | |
30 | fn iter_rows(self) -> Self::Iter { |
31 | repeat(elt:repeat(elt:"" ).take(self.cols)).take(self.rows) |
32 | } |
33 | |
34 | fn count_columns(&self) -> usize { |
35 | self.cols |
36 | } |
37 | |
38 | fn hint_count_rows(&self) -> Option<usize> { |
39 | Some(self.rows) |
40 | } |
41 | } |
42 | |