Skip to main content

made_core/ports/
leased_delivery.rs

1use crate::value_objects::{HostDeliveryLease, HostDeliveryRecord};
2
3/// One delivery, handed out with the lease that holds it.
4///
5/// The two travel together because a caller needs both and reading the
6/// record back to find its lease would race the expiry that just
7/// handed the same delivery to somebody else.
8#[derive(Debug, Clone, PartialEq, Eq)]
9pub struct LeasedDelivery {
10    lease: HostDeliveryLease,
11    record: HostDeliveryRecord,
12}
13
14impl LeasedDelivery {
15    #[must_use]
16    pub const fn new(lease: HostDeliveryLease, record: HostDeliveryRecord) -> Self {
17        Self { lease, record }
18    }
19
20    #[must_use]
21    pub const fn lease(&self) -> &HostDeliveryLease {
22        &self.lease
23    }
24
25    #[must_use]
26    pub const fn record(&self) -> &HostDeliveryRecord {
27        &self.record
28    }
29
30    #[must_use]
31    pub fn into_parts(self) -> (HostDeliveryLease, HostDeliveryRecord) {
32        (self.lease, self.record)
33    }
34}