use super::super::{
AttemptTokenBodyConflict, BindingEpoch, BindingRequiredEnvelope, ClosureCheckedEnvelope,
ClosureRefusalReason, ClosureSnapshot, ConnectionConversationCapacityExceeded, ConversationId,
DetachCommitted, DetachEnvelope, DetachInProgress, DetachStaleAuthority, Generation,
LeaveAttemptToken, LeaveCommitted, LeaveEnvelope, LeaveStaleAuthority,
MarkerClosureCapacityExceeded, NoBinding, ObserverBackpressure, ObserverBackpressureState,
ParticipantId, ParticipantReferenceEnvelope, ParticipantUnknown, ResponseEnvelope, Retired,
ServerDiscriminant, ServerValue, StaleAuthority,
};
use alloc::boxed::Box;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct DetachResponse {
value: ServerValue,
}
impl DetachResponse {
#[must_use]
pub const fn connection_conversation_capacity_exceeded(
request: DetachEnvelope,
limit: u64,
) -> Self {
Self {
value: ServerValue::ConnectionConversationCapacityExceeded(
ConnectionConversationCapacityExceeded::SemanticRequest {
request: ResponseEnvelope::Detach(request),
limit,
},
),
}
}
#[must_use]
pub const fn participant_unknown(request: DetachEnvelope) -> Self {
Self {
value: ServerValue::ParticipantUnknown(ParticipantUnknown {
request: ParticipantReferenceEnvelope::Detach(request),
}),
}
}
#[must_use]
pub const fn no_binding(request: DetachEnvelope) -> Self {
Self {
value: ServerValue::NoBinding(NoBinding {
request: BindingRequiredEnvelope::Detach(request),
}),
}
}
#[must_use]
pub const fn stale_authority(value: DetachStaleAuthority) -> Self {
Self {
value: ServerValue::StaleAuthority(StaleAuthority::Detach(value)),
}
}
#[must_use]
pub const fn retired(request: DetachEnvelope, retired_generation: Generation) -> Self {
Self {
value: ServerValue::Retired(Retired::Participant {
request: ParticipantReferenceEnvelope::Detach(request),
retired_generation,
}),
}
}
#[must_use]
pub const fn detach_committed(value: DetachCommitted) -> Self {
Self {
value: ServerValue::DetachCommitted(value),
}
}
#[must_use]
pub const fn detach_in_progress(value: DetachInProgress) -> Self {
Self {
value: ServerValue::DetachInProgress(value),
}
}
#[must_use]
pub const fn observer_backpressure(
request: DetachEnvelope,
committed_binding_epoch: BindingEpoch,
state: ObserverBackpressureState,
) -> Self {
Self {
value: ServerValue::ObserverBackpressure(ObserverBackpressure::Detach {
request,
committed_binding_epoch,
state,
}),
}
}
#[must_use]
pub const fn server_value(&self) -> &ServerValue {
&self.value
}
#[must_use]
pub const fn discriminant(&self) -> ServerDiscriminant {
self.value.discriminant()
}
#[must_use]
pub fn into_server_value(self) -> ServerValue {
self.value
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct LeaveResponse {
value: ServerValue,
}
impl LeaveResponse {
#[must_use]
pub const fn attempt_token_body_conflict(
token: LeaveAttemptToken,
conversation_id: ConversationId,
presented_participant_id: ParticipantId,
presented_generation: Generation,
) -> Self {
Self {
value: ServerValue::AttemptTokenBodyConflict(AttemptTokenBodyConflict::Leave {
token,
conversation_id,
presented_participant_id,
presented_generation,
}),
}
}
#[must_use]
pub const fn connection_conversation_capacity_exceeded(
request: LeaveEnvelope,
limit: u64,
) -> Self {
Self {
value: ServerValue::ConnectionConversationCapacityExceeded(
ConnectionConversationCapacityExceeded::SemanticRequest {
request: ResponseEnvelope::Leave(request),
limit,
},
),
}
}
#[must_use]
pub const fn participant_unknown(request: LeaveEnvelope) -> Self {
Self {
value: ServerValue::ParticipantUnknown(ParticipantUnknown {
request: ParticipantReferenceEnvelope::Leave(request),
}),
}
}
#[must_use]
pub const fn no_binding(request: LeaveEnvelope) -> Self {
Self {
value: ServerValue::NoBinding(NoBinding {
request: BindingRequiredEnvelope::Leave(request),
}),
}
}
#[must_use]
pub const fn stale_authority(value: LeaveStaleAuthority) -> Self {
Self {
value: ServerValue::StaleAuthority(StaleAuthority::Leave(value)),
}
}
#[must_use]
pub const fn retired(request: LeaveEnvelope, retired_generation: Generation) -> Self {
Self {
value: ServerValue::Retired(Retired::Participant {
request: ParticipantReferenceEnvelope::Leave(request),
retired_generation,
}),
}
}
#[must_use]
pub fn marker_closure_capacity_exceeded(
request: LeaveEnvelope,
snapshot: ClosureSnapshot,
reason: ClosureRefusalReason,
) -> Self {
Self {
value: ServerValue::MarkerClosureCapacityExceeded(Box::new(
MarkerClosureCapacityExceeded {
request: ClosureCheckedEnvelope::Leave(request),
snapshot,
reason,
},
)),
}
}
#[must_use]
pub const fn leave_committed(value: LeaveCommitted) -> Self {
Self {
value: ServerValue::LeaveCommitted(value),
}
}
#[must_use]
pub const fn observer_backpressure(
request: LeaveEnvelope,
state: ObserverBackpressureState,
prior_terminal_cell_exists: bool,
) -> Self {
Self {
value: ServerValue::ObserverBackpressure(ObserverBackpressure::Leave {
request,
state,
prior_terminal_cell_exists,
}),
}
}
#[must_use]
pub const fn server_value(&self) -> &ServerValue {
&self.value
}
#[must_use]
pub const fn discriminant(&self) -> ServerDiscriminant {
self.value.discriminant()
}
#[must_use]
pub fn into_server_value(self) -> ServerValue {
self.value
}
}