Skip to main content

made_core/ports/
processed_outcome.rs

1use crate::value_objects::{
2    HostDeliveryRecord, HostDeliveryStateKind, IntegratorFence, ProcessedActionRef,
3};
4
5/// What the ledger did with a host's claim to have acted.
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub enum ProcessedOutcome {
8    /// Closed by this act.
9    Processed(HostDeliveryRecord),
10    /// Already closed by the same act; nothing changed.
11    AlreadyProcessed(HostDeliveryRecord),
12    /// Already closed by a different act.
13    Conflict { existing: Box<ProcessedActionRef> },
14    /// Nothing was acknowledged yet, so there is nothing to close.
15    ///
16    /// A host that claims to have acted on something it never said it
17    /// received has lost track of which delivery it is answering, and
18    /// accepting the claim would close a hand-off nobody made.
19    NotAcknowledged { state: HostDeliveryStateKind },
20    /// The caller's generation is not the one currently bound.
21    FenceRejected { current: IntegratorFence },
22    /// The delivery belongs to a different host generation.
23    LeaseNotOwned,
24}
25
26impl ProcessedOutcome {
27    #[must_use]
28    pub const fn record(&self) -> Option<&HostDeliveryRecord> {
29        match self {
30            Self::Processed(record) | Self::AlreadyProcessed(record) => Some(record),
31            _ => None,
32        }
33    }
34
35    #[must_use]
36    pub const fn is_closed(&self) -> bool {
37        matches!(self, Self::Processed(_) | Self::AlreadyProcessed(_))
38    }
39}