tabled/grid/records/
empty_records.rs

1//! An empty [`Records`] implementation.
2
3use core::iter::{repeat_n, RepeatN};
4
5use super::Records;
6
7/// Empty representation of [`Records`].
8#[derive(Debug, Default, Clone)]
9pub struct EmptyRecords {
10    rows: usize,
11    cols: usize,
12}
13
14impl 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
21impl From<(usize, usize)> for EmptyRecords {
22    fn from((count_rows, count_columns): (usize, usize)) -> Self {
23        Self::new(count_rows, count_columns)
24    }
25}
26
27impl Records for EmptyRecords {
28    type Iter = RepeatN<RepeatN<&'static str>>;
29
30    fn iter_rows(self) -> Self::Iter {
31        repeat_n(repeat_n("", self.cols), 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}