liminal_protocol/wire/authority/
enrollment.rs1use alloc::boxed::Box;
4
5use super::super::{
6 ConnectionConversationBindingOccupied, ConnectionConversationCapacityExceeded,
7 ConversationOrderExhausted, ConversationSequenceExhausted, EnrollBound, EnrollmentEnvelope,
8 EnrollmentKnown, EnrollmentReceiptCapacityScope, Generation, IdentityCapacityExceeded,
9 MarkerClosureCapacityExceeded, ObserverBackpressure, ObserverBackpressureState,
10 ReceiptCapacityExceeded, ReceiptExpired, ReceiptExpiryReason, ReceiptReplay, ResponseEnvelope,
11 Retired, ServerDiscriminant, ServerValue,
12};
13
14#[derive(Clone, Debug, PartialEq, Eq)]
19pub struct EnrollmentResponse {
20 value: ServerValue,
21}
22
23impl EnrollmentResponse {
24 #[must_use]
27 pub const fn connection_conversation_capacity_exceeded(
28 request: EnrollmentEnvelope,
29 limit: u64,
30 ) -> Self {
31 Self {
32 value: ServerValue::ConnectionConversationCapacityExceeded(
33 ConnectionConversationCapacityExceeded::SemanticRequest {
34 request: ResponseEnvelope::Enrollment(request),
35 limit,
36 },
37 ),
38 }
39 }
40
41 #[must_use]
44 pub const fn connection_conversation_binding_occupied(request: &EnrollmentEnvelope) -> Self {
45 Self {
46 value: ServerValue::ConnectionConversationBindingOccupied(
47 ConnectionConversationBindingOccupied::Enrollment {
48 conversation_id: request.conversation_id,
49 enrollment_token: request.enrollment_token,
50 },
51 ),
52 }
53 }
54
55 pub(crate) const fn from_conversation_order_exhausted(
61 value: Box<ConversationOrderExhausted>,
62 ) -> Self {
63 Self {
64 value: ServerValue::ConversationOrderExhausted(value),
65 }
66 }
67
68 pub(crate) const fn from_retired(value: Retired) -> Self {
73 Self {
74 value: ServerValue::Retired(value),
75 }
76 }
77
78 pub(crate) const fn from_marker_closure_capacity_exceeded(
84 value: Box<MarkerClosureCapacityExceeded>,
85 ) -> Self {
86 Self {
87 value: ServerValue::MarkerClosureCapacityExceeded(value),
88 }
89 }
90
91 #[must_use]
93 pub const fn enroll_bound(value: EnrollBound) -> Self {
94 Self {
95 value: ServerValue::EnrollBound(value),
96 }
97 }
98
99 #[must_use]
102 pub const fn enrollment_known(value: EnrollmentKnown) -> Self {
103 Self {
104 value: ServerValue::EnrollmentKnown(value),
105 }
106 }
107
108 pub(crate) const fn from_receipt_expired(value: ReceiptExpired) -> Self {
113 Self {
114 value: ServerValue::ReceiptExpired(value),
115 }
116 }
117
118 #[must_use]
128 pub const fn receipt_expired(
129 request: &EnrollmentEnvelope,
130 participant_id: u64,
131 result_generation: Generation,
132 current_generation: Generation,
133 reason: ReceiptExpiryReason,
134 ) -> Self {
135 Self {
136 value: ServerValue::ReceiptExpired(ReceiptExpired::Enrollment {
137 conversation_id: request.conversation_id,
138 token: request.enrollment_token,
139 participant_id,
140 result_generation,
141 current_generation,
142 reason,
143 }),
144 }
145 }
146
147 #[must_use]
150 pub const fn receipt_capacity_exceeded(
151 request: EnrollmentEnvelope,
152 scope: EnrollmentReceiptCapacityScope,
153 limit: u64,
154 occupied: u64,
155 ) -> Self {
156 Self {
157 value: ServerValue::ReceiptCapacityExceeded(ReceiptCapacityExceeded::Enrollment {
158 request,
159 scope,
160 limit,
161 occupied,
162 }),
163 }
164 }
165
166 #[must_use]
168 pub const fn identity_capacity_exceeded(value: IdentityCapacityExceeded) -> Self {
169 Self {
170 value: ServerValue::IdentityCapacityExceeded(value),
171 }
172 }
173
174 #[must_use]
177 pub const fn observer_backpressure(
178 request: EnrollmentEnvelope,
179 state: ObserverBackpressureState,
180 ) -> Self {
181 Self {
182 value: ServerValue::ObserverBackpressure(ObserverBackpressure::Enrollment {
183 request,
184 state,
185 }),
186 }
187 }
188
189 pub(crate) const fn from_observer_backpressure(value: ObserverBackpressure) -> Self {
192 Self {
193 value: ServerValue::ObserverBackpressure(value),
194 }
195 }
196
197 pub(crate) const fn from_conversation_sequence_exhausted(
202 value: Box<ConversationSequenceExhausted>,
203 ) -> Self {
204 Self {
205 value: ServerValue::ConversationSequenceExhausted(value),
206 }
207 }
208
209 #[must_use]
212 pub const fn bound(value: EnrollBound) -> Self {
213 Self {
214 value: ServerValue::Bound(ReceiptReplay::Enrollment(value)),
215 }
216 }
217
218 #[must_use]
221 pub const fn unbound_receipt(value: EnrollBound) -> Self {
222 Self {
223 value: ServerValue::UnboundReceipt(ReceiptReplay::Enrollment(value)),
224 }
225 }
226
227 pub(crate) const fn from_bound(value: ReceiptReplay) -> Self {
230 Self {
231 value: ServerValue::Bound(value),
232 }
233 }
234
235 pub(crate) const fn from_unbound_receipt(value: ReceiptReplay) -> Self {
238 Self {
239 value: ServerValue::UnboundReceipt(value),
240 }
241 }
242
243 #[must_use]
245 pub const fn server_value(&self) -> &ServerValue {
246 &self.value
247 }
248
249 #[must_use]
251 pub const fn discriminant(&self) -> ServerDiscriminant {
252 self.value.discriminant()
253 }
254
255 #[must_use]
257 pub fn into_server_value(self) -> ServerValue {
258 self.value
259 }
260}