Skip to main content

appcore_contracts/policy/
storage.rs

1// =============================================================================
2//        #######
3//     ###       ###     F: storage.rs
4//    ##   ## ##   ##    P: AppCore-Runtime
5//         ## ##
6//                       C: 2026/07/22 15:41:18 by dnettoRaw
7//    ##   ## ##   ##    U: 2026/07/22 15:41:18 by dnettoRaw
8//      ###########      S: 1.0.1-rc.8
9// =============================================================================
10
11use super::*;
12
13/// Required persistence durability.
14#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
15#[serde(rename_all = "snake_case")]
16pub enum StorageDurability {
17    /// Data may be discarded when the process exits.
18    Ephemeral,
19    /// Data must survive process restarts on the same node.
20    #[default]
21    Local,
22    /// Data must use a durable provider selected by deployment.
23    Durable,
24}
25
26/// Application storage requirements without provider or path decisions.
27#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
28pub struct StorageRequirements {
29    durability: StorageDurability,
30    minimum_bytes: u64,
31    shared: bool,
32}
33
34impl StorageRequirements {
35    /// Creates provider-independent storage requirements.
36    pub fn new(durability: StorageDurability, minimum_bytes: u64, shared: bool) -> Self {
37        Self {
38            durability,
39            minimum_bytes,
40            shared,
41        }
42    }
43
44    /// Returns the required durability.
45    pub fn durability(&self) -> StorageDurability {
46        self.durability
47    }
48
49    /// Returns the minimum requested capacity.
50    pub fn minimum_bytes(&self) -> u64 {
51        self.minimum_bytes
52    }
53
54    /// Reports whether storage must be shared across nodes.
55    pub fn is_shared(&self) -> bool {
56        self.shared
57    }
58}