Skip to main content

postproject_core/
commit.rs

1//! Atomic results of production commits.
2
3use crate::{ProductionId, Revision};
4
5/// The production and revision actually produced by a successful commit.
6///
7/// An absent revision is an explicit no-change outcome. It never identifies
8/// another transaction's revision, even when the production is nonempty.
9#[derive(Clone, Debug, Eq, PartialEq)]
10pub struct CommitReceipt {
11    production_id: ProductionId,
12    revision: Option<Revision>,
13}
14
15impl CommitReceipt {
16    /// Creates a receipt from the atomic persistence result.
17    #[must_use]
18    pub const fn new(production_id: ProductionId, revision: Option<Revision>) -> Self {
19        Self {
20            production_id,
21            revision,
22        }
23    }
24
25    /// Returns the production whose commit succeeded.
26    #[must_use]
27    pub const fn production_id(&self) -> ProductionId {
28        self.production_id
29    }
30
31    /// Returns this commit's new revision, or `None` when no revision was made.
32    #[must_use]
33    pub const fn revision(&self) -> Option<&Revision> {
34        self.revision.as_ref()
35    }
36}