pub const PROJECT_STATUS: &str = "prototype";
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
pub struct TableShape {
rows: u64,
columns: u64,
}
impl TableShape {
#[must_use]
pub const fn new(rows: u64, columns: u64) -> Self {
Self { rows, columns }
}
#[must_use]
pub const fn rows(self) -> u64 {
self.rows
}
#[must_use]
pub const fn columns(self) -> u64 {
self.columns
}
#[must_use]
pub const fn is_empty(self) -> bool {
self.rows == 0 || self.columns == 0
}
#[must_use]
pub const fn checked_cell_count(self) -> Option<u64> {
self.rows.checked_mul(self.columns)
}
}
#[cfg(test)]
mod tests {
use super::TableShape;
#[test]
fn reports_shape_metadata() {
let shape = TableShape::new(12, 4);
assert_eq!(shape.rows(), 12);
assert_eq!(shape.columns(), 4);
assert_eq!(shape.checked_cell_count(), Some(48));
assert!(!shape.is_empty());
}
#[test]
fn treats_a_zero_dimension_as_empty() {
assert!(TableShape::new(0, 4).is_empty());
assert!(TableShape::new(4, 0).is_empty());
}
#[test]
fn detects_cell_count_overflow() {
assert_eq!(TableShape::new(u64::MAX, 2).checked_cell_count(), None);
}
}