papergrid/dimension/
mod.rs

1//! The module contains an [`Dimension`] trait and its implementations.
2
3#[cfg(feature = "std")]
4pub mod compact;
5#[cfg(feature = "std")]
6pub mod iterable;
7#[cfg(feature = "std")]
8pub mod peekable;
9
10/// Dimension of a grid.
11///
12/// It's a friend trait of [`Estimate`].
13pub trait Dimension {
14    /// Get a column width by index.
15    fn get_width(&self, column: usize) -> usize;
16
17    /// Get a row height by index.
18    fn get_height(&self, row: usize) -> usize;
19}
20
21impl<T> Dimension for &T
22where
23    T: Dimension,
24{
25    fn get_height(&self, row: usize) -> usize {
26        T::get_height(self, row)
27    }
28
29    fn get_width(&self, column: usize) -> usize {
30        T::get_width(self, column)
31    }
32}
33
34/// Dimension estimation of a grid.
35///
36/// It's a friend trait of [`Dimension`].
37pub trait Estimate<R, C> {
38    /// Estimates a metric.
39    fn estimate(&mut self, records: R, config: &C);
40}
41
42impl<T, R, C> Estimate<R, C> for &mut T
43where
44    T: Estimate<R, C>,
45{
46    fn estimate(&mut self, records: R, config: &C) {
47        T::estimate(self, records, config)
48    }
49}