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
9pub(crate) use guard::first_duplicate_position;
10
11/// An ordered collection of at most `N` items.
12#[derive(Debug, Clone, PartialEq, Eq, Hash)]
13pub struct Bounded<T, const N: usize>(Vec<T>);
14
15/// An ordered collection of at least one and at most `N` items.
16///
17/// The first item is a field, so non-emptiness is the shape of the value rather than a property a road checks.
18#[derive(Debug, Clone, PartialEq, Eq, Hash)]
19pub struct NonEmpty<T, const N: usize> {
20 head: T,
21 tail: Vec<T>,
22}
23
24/// A non-empty bounded roster whose caller-declared keys are unique.
25#[derive(Debug, Clone, PartialEq, Eq, Hash)]
26pub struct KeyedRoster<T, K, const N: usize> {
27 members: NonEmpty<T, N>,
28 keys: NonEmpty<K, N>,
29}
30
31/// One payload assignment for every member of a caller-keyed denominator roster.
32///
33/// The denominator and payload rosters share denominator order by construction.
34#[derive(Debug, Clone, PartialEq, Eq, Hash)]
35pub struct KeyedRosterAssignment<D, K, P, S, const N: usize> {
36 denominator: KeyedRoster<D, K, N>,
37 payloads: KeyedRoster<P, S, N>,
38}
39
40/// One duplicated key and every declaration position at which it occurred.
41#[derive(Debug, Clone, PartialEq, Eq, Hash)]
42pub struct DuplicateKey<K, const N: usize> {
43 key: K,
44 first: usize,
45 repeated: NonEmpty<usize, N>,
46}
47
48/// One offered item whose referenced roster key is foreign.
49#[derive(Debug, Clone, PartialEq, Eq, Hash)]
50pub struct ForeignRosterReference<K> {
51 key: K,
52 offered_position: usize,
53}
54
55/// One denominator member for which no payload was offered.
56#[derive(Debug, Clone, PartialEq, Eq, Hash)]
57pub struct UnassignedRosterMember<K> {
58 key: K,
59 denominator_position: usize,
60}
61
62/// A non-empty ordered collection together with its constructor-derived capping posture.
63#[derive(Debug, Clone, PartialEq, Eq, Hash)]
64pub struct Capped<T, const N: usize> {
65 items: NonEmpty<T, N>,
66 capping: Capping,
67}
68
69/// Whether a capped list holds everything that was offered to it.
70#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
71pub enum Capping {
72 /// Everything offered fit.
73 Complete,
74 /// The list filled and the rest was dropped.
75 Truncated {
76 /// How many offered items the list did not keep.
77 omitted: usize,
78 },
79}
80
81/// The exact magnitude refused because more items were offered than a ceiling admits.
82#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
83pub struct Overflow {
84 /// The most items the bound admits.
85 pub capacity: usize,
86 /// How many items were offered.
87 pub offered: usize,
88}
89
90/// No item was offered where at least one is required.
91#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
92pub struct Empty;
93
94/// How construction of a required non-empty collection refuses.
95#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
96pub enum NonEmptyError {
97 /// Nothing was offered.
98 Empty(Empty),
99 /// Too much was offered.
100 Overflow(Overflow),
101}
102
103/// How construction of a caller-keyed roster refuses.
104#[derive(Debug, Clone, PartialEq, Eq, Hash)]
105pub enum KeyedRosterError<K, const N: usize> {
106 /// Nothing was offered.
107 Empty(Empty),
108 /// Too much was offered.
109 Overflow(Overflow),
110 /// One or more caller-declared keys occurred more than once.
111 DuplicateKeys(NonEmpty<DuplicateKey<K, N>, N>),
112}
113
114/// How an offered payload roster refuses exact assignment to a keyed denominator.
115#[derive(Debug, Clone, PartialEq, Eq, Hash)]
116pub enum KeyedRosterAssignmentError<K, S, const N: usize> {
117 /// Nothing was offered.
118 Empty(Empty),
119 /// Too much was offered.
120 Overflow(Overflow),
121 /// One or more offered payloads name a key outside the denominator.
122 ForeignReferences(NonEmpty<ForeignRosterReference<K>, N>),
123 /// One or more denominator keys were referenced more than once.
124 DuplicateReferences(NonEmpty<DuplicateKey<K, N>, N>),
125 /// One or more caller-declared payload-seat keys were reused.
126 ReusedPayloadSeats(NonEmpty<DuplicateKey<S, N>, N>),
127 /// One or more denominator members received no payload.
128 MissingMembers(NonEmpty<UnassignedRosterMember<K>, N>),
129}