Skip to main content

bornera_core/operation/
outcome.rs

1//! Mechanical operation outcomes without protocol retry meaning.
2
3use crate::{CloseReason, Delivery};
4
5/// The transport-owned phase of an accepted operation.
6#[derive(Clone, Copy, Debug, Eq, PartialEq)]
7#[non_exhaustive]
8pub enum OperationPhase {
9    /// The complete frame is queued but transport write ownership has not begun.
10    Queued,
11    /// At least one byte was written, but the writer still owns an unwritten tail.
12    Writing,
13    /// The complete frame left local write ownership and a reply may arrive.
14    AwaitingReply,
15    /// One terminal outcome has been emitted.
16    Terminal,
17}
18
19/// A mechanical failure observed by the connection owner.
20#[derive(Clone, Copy, Debug, Eq, PartialEq)]
21#[non_exhaustive]
22pub enum OperationFailure {
23    /// The original absolute deadline elapsed.
24    DeadlineElapsed,
25    /// The owning connection epoch closed.
26    ConnectionClosed(CloseReason),
27    /// The received reply named another live operation instead of the FIFO front.
28    MatchKeyMismatch {
29        /// Match key required by the FIFO front.
30        expected: crate::MatchKey,
31        /// Match key carried by the received reply.
32        received: crate::MatchKey,
33    },
34}
35
36/// Exactly one terminal outcome for an accepted operation.
37#[derive(Clone, Debug, Eq, PartialEq)]
38#[non_exhaustive]
39pub enum OperationOutcome<F> {
40    /// The matching discipline assigned a reply to this operation.
41    Reply(F),
42    /// The complete application frame left Bornera write ownership without awaiting a reply.
43    ///
44    /// A buffering transport may still own encoded output that has not reached the
45    /// operating system.
46    WriteComplete {
47        /// What local transport ownership can prove.
48        delivery: Delivery,
49    },
50    /// Mechanical failure with conservative delivery certainty.
51    Failed {
52        /// The observed failure.
53        failure: OperationFailure,
54        /// What local transport ownership can prove.
55        delivery: Delivery,
56    },
57    /// Explicit local cancellation with conservative delivery certainty.
58    Cancelled {
59        /// What local transport ownership can prove.
60        delivery: Delivery,
61    },
62}
63
64impl<F: calandria::Retained> calandria::Retained for OperationOutcome<F> {
65    fn retained_bytes(&self) -> calandria::RetainedBytes {
66        match self {
67            Self::Reply(frame) => frame.retained_bytes(),
68            Self::WriteComplete { .. } | Self::Failed { .. } | Self::Cancelled { .. } => {
69                calandria::RetainedBytes::ZERO
70            }
71        }
72    }
73}