#![forbid(unsafe_code)]
#![doc = include_str!("../README.md")]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Dimension(usize);
impl Dimension {
pub const ONE: Self = Self(1);
pub const TWO: Self = Self(2);
pub const THREE: Self = Self(3);
#[must_use]
pub const fn new(value: usize) -> Option<Self> {
if value == 0 { None } else { Some(Self(value)) }
}
#[must_use]
pub const fn new_unchecked(value: usize) -> Self {
Self(value)
}
#[must_use]
pub const fn value(self) -> usize {
self.0
}
#[must_use]
pub const fn is_spatial(self) -> bool {
self.0 <= 3
}
}
#[cfg(test)]
mod tests {
use super::Dimension;
#[test]
fn validates_positive_dimensions() {
assert_eq!(Dimension::new(0), None);
assert_eq!(Dimension::new(2), Some(Dimension::TWO));
assert_eq!(Dimension::THREE.value(), 3);
assert!(Dimension::THREE.is_spatial());
assert!(!Dimension::new_unchecked(4).is_spatial());
}
}