liminal_protocol/algebra/
types.rs1use core::fmt;
2
3#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
5pub struct ResourceVector {
6 pub entries: u64,
8 pub bytes: u64,
10}
11
12impl ResourceVector {
13 #[must_use]
15 pub const fn new(entries: u64, bytes: u64) -> Self {
16 Self { entries, bytes }
17 }
18
19 #[must_use]
21 pub const fn widen(self) -> WideResourceVector {
22 WideResourceVector::new(widen_u64(self.entries), widen_u64(self.bytes))
23 }
24}
25
26#[allow(clippy::cast_lossless)]
29pub(super) const fn widen_u64(value: u64) -> u128 {
30 value as u128
31}
32
33#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
35pub struct WideResourceVector {
36 pub entries: u128,
38 pub bytes: u128,
40}
41
42impl WideResourceVector {
43 #[must_use]
45 pub const fn new(entries: u128, bytes: u128) -> Self {
46 Self { entries, bytes }
47 }
48
49 #[must_use]
51 pub const fn is_zero(self) -> bool {
52 self.entries == 0 && self.bytes == 0
53 }
54}
55
56#[derive(Clone, Copy, Debug, PartialEq, Eq)]
58pub enum ResourceDimension {
59 Entries,
61 Bytes,
63}
64
65#[derive(Clone, Copy, Debug, PartialEq, Eq)]
67pub enum BaselineError {
68 MarkerCreditsExceedIdentitySlots {
70 identity_slots: u64,
72 marker_credits: u64,
74 },
75}
76
77impl fmt::Display for BaselineError {
78 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
79 match self {
80 Self::MarkerCreditsExceedIdentitySlots {
81 identity_slots,
82 marker_credits,
83 } => write!(
84 formatter,
85 "marker credits ({marker_credits}) exceed identity slots ({identity_slots})"
86 ),
87 }
88 }
89}
90
91#[derive(Clone, Copy, Debug, PartialEq, Eq)]
93pub struct MandatoryCapacity {
94 pub debt: WideResourceVector,
96 pub absolute_fit: bool,
98 pub debt_within_mandatory_bound: bool,
100}
101
102impl MandatoryCapacity {
103 #[must_use]
105 pub const fn is_legal(self) -> bool {
106 self.absolute_fit && self.debt_within_mandatory_bound
107 }
108}
109
110#[derive(Clone, Copy, Debug, PartialEq, Eq)]
112pub struct RecoveryTransfer {
113 pub baseline: WideResourceVector,
115 pub remaining_recovery_claim: ResourceVector,
117}
118
119#[derive(Clone, Copy, Debug, PartialEq, Eq)]
121pub struct RecoveryTransferError {
122 pub dimension: ResourceDimension,
125}
126
127impl fmt::Display for RecoveryTransferError {
128 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
129 write!(
130 formatter,
131 "recovery charge exceeds remaining {:?} claim",
132 self.dimension
133 )
134 }
135}
136
137#[derive(Clone, Copy, Debug, PartialEq, Eq)]
139pub struct FloorComputation {
140 pub member_cursor: u64,
142 pub preferred_floor: u128,
144 pub resulting_floor: u128,
146}