Skip to main content

use_manifold/
lib.rs

1#![forbid(unsafe_code)]
2#![doc = include_str!("../README.md")]
3
4/// A non-negative manifold dimension.
5#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
6pub struct ManifoldDimension(usize);
7
8impl ManifoldDimension {
9    /// Creates a manifold dimension.
10    #[must_use]
11    pub const fn new(value: usize) -> Option<Self> {
12        Some(Self(value))
13    }
14
15    /// Returns the numeric dimension.
16    #[must_use]
17    pub const fn value(self) -> usize {
18        self.0
19    }
20}
21
22/// Boundary metadata for a manifold.
23#[derive(Debug, Clone, Copy, PartialEq, Eq)]
24pub enum BoundaryKind {
25    /// The manifold has no boundary.
26    WithoutBoundary,
27    /// The manifold has a boundary.
28    WithBoundary,
29    /// Boundary information is intentionally unspecified.
30    Unspecified,
31}
32
33/// A lightweight manifold descriptor.
34#[derive(Debug, Clone, Copy, PartialEq, Eq)]
35pub struct Manifold {
36    dimension: ManifoldDimension,
37    boundary_kind: BoundaryKind,
38}
39
40impl Manifold {
41    /// Creates a manifold descriptor.
42    #[must_use]
43    pub const fn new(dimension: ManifoldDimension, boundary_kind: BoundaryKind) -> Self {
44        Self {
45            dimension,
46            boundary_kind,
47        }
48    }
49
50    /// Returns the dimension.
51    #[must_use]
52    pub const fn dimension(self) -> ManifoldDimension {
53        self.dimension
54    }
55
56    /// Returns the boundary kind.
57    #[must_use]
58    pub const fn boundary_kind(self) -> BoundaryKind {
59        self.boundary_kind
60    }
61}
62
63#[cfg(test)]
64mod tests {
65    use super::{BoundaryKind, Manifold, ManifoldDimension};
66
67    #[test]
68    fn stores_manifold_metadata() {
69        let dimension = ManifoldDimension::new(2).expect("valid dimension");
70        let manifold = Manifold::new(dimension, BoundaryKind::WithoutBoundary);
71
72        assert_eq!(dimension.value(), 2);
73        assert_eq!(manifold.dimension(), dimension);
74        assert_eq!(manifold.boundary_kind(), BoundaryKind::WithoutBoundary);
75    }
76}