Skip to main content

bornera_core/connection/
transition.rs

1//! Observable result of applying one machine command or input.
2
3use crate::ConnectionEffect;
4
5/// Whether an input changed the current epoch.
6#[derive(Clone, Copy, Debug, Eq, PartialEq)]
7#[non_exhaustive]
8pub enum InputDisposition {
9    /// The input changed current state or emitted a required effect.
10    Applied,
11    /// An old epoch produced the input; current state was untouched.
12    IgnoredStaleEpoch,
13    /// No retained slot owns the named operation.
14    IgnoredUnknownOperation,
15    /// The effect does not own the named operation's write.
16    IgnoredStaleEffect,
17    /// The operation already emitted its terminal outcome.
18    AlreadyTerminal,
19    /// The input is not valid in the operation or connection phase.
20    IgnoredInvalidPhase,
21    /// Current-epoch input poisoned the epoch and forced closure.
22    Fault,
23}
24
25/// Result of explicit cancellation.
26#[derive(Clone, Copy, Debug, Eq, PartialEq)]
27#[non_exhaustive]
28pub enum CancelOutcome {
29    /// Queued work was removed before transport write ownership.
30    CancelledNotSent,
31    /// Local observation ended, but the peer may have received the work.
32    ObservationCancelled {
33        /// Conservative delivery certainty.
34        delivery: crate::Delivery,
35    },
36    /// The operation was already terminal or is no longer retained.
37    AlreadyTerminal,
38}
39
40/// Data-only effects and classification produced by one state transition.
41#[must_use = "connection transitions contain required deadline, closure, and publication effects"]
42#[derive(Clone, Debug, Eq, PartialEq)]
43pub struct ConnectionTransition<F = ()> {
44    disposition: InputDisposition,
45    cancel_outcome: Option<CancelOutcome>,
46    effects: Vec<ConnectionEffect<F>>,
47}
48
49impl<F> ConnectionTransition<F> {
50    pub(crate) fn new(disposition: InputDisposition) -> Self {
51        Self {
52            disposition,
53            cancel_outcome: None,
54            effects: Vec::new(),
55        }
56    }
57
58    pub(crate) fn cancelled(mut self, outcome: CancelOutcome) -> Self {
59        self.cancel_outcome = Some(outcome);
60        self
61    }
62
63    pub(crate) fn push(&mut self, effect: ConnectionEffect<F>) {
64        self.effects.push(effect);
65    }
66
67    /// Returns how the machine classified the input.
68    pub const fn disposition(&self) -> InputDisposition {
69        self.disposition
70    }
71
72    /// Returns the explicit cancellation result, when applicable.
73    pub const fn cancel_outcome(&self) -> Option<CancelOutcome> {
74        self.cancel_outcome
75    }
76
77    /// Returns emitted effects in deterministic owner order.
78    pub fn effects(&self) -> &[ConnectionEffect<F>] {
79        &self.effects
80    }
81
82    /// Transfers the emitted effects to the caller.
83    pub fn into_effects(self) -> Vec<ConnectionEffect<F>> {
84        self.effects
85    }
86}