Skip to main content

made_core/ports/artifact/
artifact_snapshot.rs

1use serde::{Deserialize, Serialize};
2
3use super::{ArtifactIdempotencyKey, ArtifactProtectionStatus, ArtifactRecord};
4
5/// Durable store-side protection. A clock never expires these references.
6#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
7pub struct ArtifactSnapshot {
8    pub key: ArtifactIdempotencyKey,
9    pub records: Vec<ArtifactRecord>,
10    pub status: ArtifactProtectionStatus,
11}
12
13impl ArtifactSnapshot {
14    #[must_use]
15    pub fn protected(key: ArtifactIdempotencyKey, records: Vec<ArtifactRecord>) -> Self {
16        Self {
17            key,
18            records,
19            status: ArtifactProtectionStatus::Protected,
20        }
21    }
22
23    #[must_use]
24    pub fn is_released(&self) -> bool {
25        self.status == ArtifactProtectionStatus::Released
26    }
27
28    pub fn release(&mut self) {
29        self.status = ArtifactProtectionStatus::Released;
30    }
31
32    #[must_use]
33    pub fn is_protected(&self) -> bool {
34        self.status == ArtifactProtectionStatus::Protected
35    }
36}