From ef24de24a82fe681581cc130f342363c47c0969a Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 7 Jun 2024 07:48:48 +0200 Subject: Merging upstream version 1.75.0+dfsg1. Signed-off-by: Daniel Baumann --- .../tabled/src/grid/dimension/const_dimension.rs | 70 ++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 vendor/tabled/src/grid/dimension/const_dimension.rs (limited to 'vendor/tabled/src/grid/dimension/const_dimension.rs') diff --git a/vendor/tabled/src/grid/dimension/const_dimension.rs b/vendor/tabled/src/grid/dimension/const_dimension.rs new file mode 100644 index 000000000..450b1abfe --- /dev/null +++ b/vendor/tabled/src/grid/dimension/const_dimension.rs @@ -0,0 +1,70 @@ +//! Module contains a dimension estimator for [`CompactTable`] +//! +//! [`CompactTable`]: crate::tables::CompactTable + +use crate::grid::dimension::{Dimension, Estimate}; + +/// A constant size dimension or a value dimension. +#[derive(Debug, Clone, Copy)] +pub struct ConstDimension { + height: ConstSize, + width: ConstSize, +} + +impl ConstDimension { + /// Returns a new dimension object with a given estimates. + pub const fn new(width: ConstSize, height: ConstSize) -> Self { + Self { width, height } + } +} + +impl Dimension for ConstDimension { + fn get_width(&self, column: usize) -> usize { + match self.width { + ConstSize::List(list) => list[column], + ConstSize::Value(val) => val, + } + } + + fn get_height(&self, row: usize) -> usize { + match self.height { + ConstSize::List(list) => list[row], + ConstSize::Value(val) => val, + } + } +} + +impl From> + for (ConstSize, ConstSize) +{ + fn from(value: ConstDimension) -> Self { + (value.width, value.height) + } +} + +impl Estimate + for ConstDimension +{ + fn estimate(&mut self, _: R, _: &D) {} +} + +/// Const size represents either a const array values or a single value which responsible for the whole list. +#[derive(Debug, Clone, Copy)] +pub enum ConstSize { + /// A constant array of estimates. + List([usize; N]), + /// A value which act as a single estimate for all entries. + Value(usize), +} + +impl From for ConstSize<0> { + fn from(value: usize) -> Self { + ConstSize::Value(value) + } +} + +impl From<[usize; N]> for ConstSize { + fn from(value: [usize; N]) -> Self { + ConstSize::List(value) + } +} -- cgit v1.2.3