Skip to main content

made_core/ports/
enqueue_outcome.rs

1use crate::value_objects::HostDeliveryRecord;
2
3/// What the ledger did with an offered delivery.
4///
5/// Idempotent by identity: the same item offered to the same
6/// destination twice is one delivery, and the second offer hands back
7/// what is already there rather than a second copy of it. That is what
8/// lets a projector replay the feed after a restart without doubling
9/// every hand-off it already made.
10#[derive(Debug, Clone, PartialEq, Eq)]
11pub enum EnqueueOutcome {
12    /// New: the ledger is holding it now.
13    Enqueued(HostDeliveryRecord),
14    /// Already held, in whatever state it had reached.
15    AlreadyQueued(HostDeliveryRecord),
16}
17
18impl EnqueueOutcome {
19    #[must_use]
20    pub const fn record(&self) -> &HostDeliveryRecord {
21        match self {
22            Self::Enqueued(record) | Self::AlreadyQueued(record) => record,
23        }
24    }
25
26    #[must_use]
27    pub const fn is_new(&self) -> bool {
28        matches!(self, Self::Enqueued(_))
29    }
30
31    #[must_use]
32    pub fn into_record(self) -> HostDeliveryRecord {
33        match self {
34            Self::Enqueued(record) | Self::AlreadyQueued(record) => record,
35        }
36    }
37}