liminal_protocol/wire/authority/
lifecycle.rs1use super::super::{
5 AttemptTokenBodyConflict, BindingEpoch, BindingRequiredEnvelope, ClosureCheckedEnvelope,
6 ClosureRefusalReason, ClosureSnapshot, ConnectionConversationCapacityExceeded, ConversationId,
7 DetachCommitted, DetachEnvelope, DetachInProgress, DetachStaleAuthority, Generation,
8 LeaveAttemptToken, LeaveCommitted, LeaveEnvelope, LeaveStaleAuthority,
9 MarkerClosureCapacityExceeded, MarkerSettlementBackpressure, NoBinding, ObserverBackpressure,
10 ObserverBackpressureState, ParticipantId, ParticipantReferenceEnvelope, ParticipantUnknown,
11 ResponseEnvelope, Retired, ServerDiscriminant, ServerValue, SettlementEpoch, StaleAuthority,
12};
13
14use alloc::boxed::Box;
15
16#[derive(Clone, Debug, PartialEq, Eq)]
21pub struct DetachResponse {
22 value: ServerValue,
23}
24
25impl DetachResponse {
26 #[must_use]
29 pub const fn connection_conversation_capacity_exceeded(
30 request: DetachEnvelope,
31 limit: u64,
32 ) -> Self {
33 Self {
34 value: ServerValue::ConnectionConversationCapacityExceeded(
35 ConnectionConversationCapacityExceeded::SemanticRequest {
36 request: ResponseEnvelope::Detach(request),
37 limit,
38 },
39 ),
40 }
41 }
42
43 #[must_use]
45 pub const fn participant_unknown(request: DetachEnvelope) -> Self {
46 Self {
47 value: ServerValue::ParticipantUnknown(ParticipantUnknown {
48 request: ParticipantReferenceEnvelope::Detach(request),
49 }),
50 }
51 }
52
53 #[must_use]
56 pub const fn no_binding(request: DetachEnvelope) -> Self {
57 Self {
58 value: ServerValue::NoBinding(NoBinding {
59 request: BindingRequiredEnvelope::Detach(request),
60 }),
61 }
62 }
63
64 #[must_use]
68 pub const fn stale_authority(value: DetachStaleAuthority) -> Self {
69 Self {
70 value: ServerValue::StaleAuthority(StaleAuthority::Detach(value)),
71 }
72 }
73
74 #[must_use]
76 pub const fn retired(request: DetachEnvelope, retired_generation: Generation) -> Self {
77 Self {
78 value: ServerValue::Retired(Retired::Participant {
79 request: ParticipantReferenceEnvelope::Detach(request),
80 retired_generation,
81 }),
82 }
83 }
84
85 #[must_use]
87 pub const fn detach_committed(value: DetachCommitted) -> Self {
88 Self {
89 value: ServerValue::DetachCommitted(value),
90 }
91 }
92
93 #[must_use]
96 pub const fn detach_in_progress(value: DetachInProgress) -> Self {
97 Self {
98 value: ServerValue::DetachInProgress(value),
99 }
100 }
101
102 #[must_use]
105 pub const fn observer_backpressure(
106 request: DetachEnvelope,
107 committed_binding_epoch: BindingEpoch,
108 state: ObserverBackpressureState,
109 ) -> Self {
110 Self {
111 value: ServerValue::ObserverBackpressure(ObserverBackpressure::Detach {
112 request,
113 committed_binding_epoch,
114 state,
115 }),
116 }
117 }
118
119 #[must_use]
128 pub const fn marker_settlement_backpressure(
129 request: &DetachEnvelope,
130 refused_epoch: SettlementEpoch,
131 ) -> Self {
132 Self {
133 value: ServerValue::MarkerSettlementBackpressure(
134 MarkerSettlementBackpressure::Detach {
135 conversation_id: request.conversation_id,
136 refused_epoch,
137 },
138 ),
139 }
140 }
141
142 #[must_use]
144 pub const fn server_value(&self) -> &ServerValue {
145 &self.value
146 }
147
148 #[must_use]
150 pub const fn discriminant(&self) -> ServerDiscriminant {
151 self.value.discriminant()
152 }
153
154 #[must_use]
156 pub fn into_server_value(self) -> ServerValue {
157 self.value
158 }
159}
160
161#[derive(Clone, Debug, PartialEq, Eq)]
166pub struct LeaveResponse {
167 value: ServerValue,
168}
169
170impl LeaveResponse {
171 #[must_use]
175 pub const fn attempt_token_body_conflict(
176 token: LeaveAttemptToken,
177 conversation_id: ConversationId,
178 presented_participant_id: ParticipantId,
179 presented_generation: Generation,
180 ) -> Self {
181 Self {
182 value: ServerValue::AttemptTokenBodyConflict(AttemptTokenBodyConflict::Leave {
183 token,
184 conversation_id,
185 presented_participant_id,
186 presented_generation,
187 }),
188 }
189 }
190
191 #[must_use]
194 pub const fn connection_conversation_capacity_exceeded(
195 request: LeaveEnvelope,
196 limit: u64,
197 ) -> Self {
198 Self {
199 value: ServerValue::ConnectionConversationCapacityExceeded(
200 ConnectionConversationCapacityExceeded::SemanticRequest {
201 request: ResponseEnvelope::Leave(request),
202 limit,
203 },
204 ),
205 }
206 }
207
208 #[must_use]
210 pub const fn participant_unknown(request: LeaveEnvelope) -> Self {
211 Self {
212 value: ServerValue::ParticipantUnknown(ParticipantUnknown {
213 request: ParticipantReferenceEnvelope::Leave(request),
214 }),
215 }
216 }
217
218 #[must_use]
220 pub const fn no_binding(request: LeaveEnvelope) -> Self {
221 Self {
222 value: ServerValue::NoBinding(NoBinding {
223 request: BindingRequiredEnvelope::Leave(request),
224 }),
225 }
226 }
227
228 #[must_use]
231 pub const fn stale_authority(value: LeaveStaleAuthority) -> Self {
232 Self {
233 value: ServerValue::StaleAuthority(StaleAuthority::Leave(value)),
234 }
235 }
236
237 #[must_use]
240 pub const fn retired(request: LeaveEnvelope, retired_generation: Generation) -> Self {
241 Self {
242 value: ServerValue::Retired(Retired::Participant {
243 request: ParticipantReferenceEnvelope::Leave(request),
244 retired_generation,
245 }),
246 }
247 }
248
249 #[must_use]
252 pub fn marker_closure_capacity_exceeded(
253 request: LeaveEnvelope,
254 snapshot: ClosureSnapshot,
255 reason: ClosureRefusalReason,
256 ) -> Self {
257 Self {
258 value: ServerValue::MarkerClosureCapacityExceeded(Box::new(
259 MarkerClosureCapacityExceeded {
260 request: ClosureCheckedEnvelope::Leave(request),
261 snapshot,
262 reason,
263 },
264 )),
265 }
266 }
267
268 #[must_use]
271 pub const fn leave_committed(value: LeaveCommitted) -> Self {
272 Self {
273 value: ServerValue::LeaveCommitted(value),
274 }
275 }
276
277 #[must_use]
279 pub const fn observer_backpressure(
280 request: LeaveEnvelope,
281 state: ObserverBackpressureState,
282 prior_terminal_cell_exists: bool,
283 ) -> Self {
284 Self {
285 value: ServerValue::ObserverBackpressure(ObserverBackpressure::Leave {
286 request,
287 state,
288 prior_terminal_cell_exists,
289 }),
290 }
291 }
292
293 #[must_use]
295 pub const fn server_value(&self) -> &ServerValue {
296 &self.value
297 }
298
299 #[must_use]
301 pub const fn discriminant(&self) -> ServerDiscriminant {
302 self.value.discriminant()
303 }
304
305 #[must_use]
307 pub fn into_server_value(self) -> ServerValue {
308 self.value
309 }
310}