papergrid/records/
empty.rs

1//! An empty [`Records`] implementation.
2
3use crate::{records::Records, Position};
4
5/// Empty representation of [`Records`].
6#[derive(Debug, Default, Clone)]
7pub struct EmptyRecords {
8    rows: usize,
9    cols: usize,
10}
11
12impl EmptyRecords {
13    /// Constracts an empty representation of [`Records`] with a given shape.
14    pub fn new(rows: usize, cols: usize) -> Self {
15        Self { rows, cols }
16    }
17}
18
19impl Records for EmptyRecords {
20    fn count_rows(&self) -> usize {
21        self.rows
22    }
23
24    fn count_columns(&self) -> usize {
25        self.cols
26    }
27
28    fn get_text(&self, _: Position) -> &str {
29        ""
30    }
31
32    fn get_line(&self, _: Position, _: usize) -> &str {
33        ""
34    }
35
36    fn get_width<W>(&self, _: Position, _: W) -> usize {
37        0
38    }
39
40    fn get_line_width<W>(&self, _: Position, _: usize, _: W) -> usize {
41        0
42    }
43
44    fn count_lines(&self, _: Position) -> usize {
45        1
46    }
47
48    fn fmt_text_prefix(&self, _: &mut std::fmt::Formatter<'_>, _: Position) -> std::fmt::Result {
49        Ok(())
50    }
51
52    fn fmt_text_suffix(&self, _: &mut std::fmt::Formatter<'_>, _: Position) -> std::fmt::Result {
53        Ok(())
54    }
55}