Skip to main content

macroonz_compiler/bounded/
types.rs

1//! The bounded home's collection shapes, capping posture, and construction refusals.
2//!
3//! Declarations only.
4//! Every road that reaches a private field lives in `type_guard.rs`, this file's own child, which is what makes each ceiling structural rather than remembered.
5
6#[path = "type_guard.rs"]
7mod guard;
8
9/// An ordered collection of at most `N` items.
10#[derive(Debug, Clone, PartialEq, Eq, Hash)]
11pub struct Bounded<T, const N: usize>(Vec<T>);
12
13/// An ordered collection of at least one and at most `N` items.
14///
15/// The first item is a field, so non-emptiness is the shape of the value rather than a property a road checks.
16#[derive(Debug, Clone, PartialEq, Eq, Hash)]
17pub struct NonEmpty<T, const N: usize> {
18    head: T,
19    tail: Vec<T>,
20}
21
22/// A non-empty ordered collection together with its constructor-derived capping posture.
23#[derive(Debug, Clone, PartialEq, Eq, Hash)]
24pub struct Capped<T, const N: usize> {
25    items: NonEmpty<T, N>,
26    capping: Capping,
27}
28
29/// Whether a capped list holds everything that was offered to it.
30#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
31pub enum Capping {
32    /// Everything offered fit.
33    Complete,
34    /// The list filled and the rest was dropped.
35    Truncated {
36        /// How many offered items the list did not keep.
37        omitted: usize,
38    },
39}
40
41/// The exact magnitude refused because more items were offered than a ceiling admits.
42#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
43pub struct Overflow {
44    /// The most items the bound admits.
45    pub capacity: usize,
46    /// How many items were offered.
47    pub offered: usize,
48}
49
50/// No item was offered where at least one is required.
51#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
52pub struct Empty;
53
54/// How construction of a required non-empty collection refuses.
55#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
56pub enum NonEmptyError {
57    /// Nothing was offered.
58    Empty(Empty),
59    /// Too much was offered.
60    Overflow(Overflow),
61}