Skip to main content

ic_memory/
policy.rs

1use crate::{key::StableKey, slot::AllocationSlotDescriptor};
2
3///
4/// AllocationPolicy
5///
6/// Framework-supplied rules for whether a key may claim a slot.
7///
8/// Policy is intentionally separate from the durable ledger invariant. The
9/// ledger remembers `stable_key -> allocation_slot`; this trait lets an
10/// integration reject declarations that do not belong to its namespace or
11/// substrate-specific range before staging a generation.
12///
13/// In the default `MemoryManager` runtime, registered range claims are checked
14/// before this policy. Framework adapters should decide whether `ic-memory`
15/// range claims or their own policy is authoritative for a given ID space, then
16/// register ranges accordingly.
17pub trait AllocationPolicy {
18    /// Policy error type.
19    type Error;
20
21    /// Validate a stable key against framework naming rules.
22    fn validate_key(&self, key: &StableKey) -> Result<(), Self::Error>;
23
24    /// Validate a stable-key to allocation-slot claim.
25    fn validate_slot(
26        &self,
27        key: &StableKey,
28        slot: &AllocationSlotDescriptor,
29    ) -> Result<(), Self::Error>;
30
31    /// Validate a reserved stable-key to allocation-slot claim.
32    fn validate_reserved_slot(
33        &self,
34        key: &StableKey,
35        slot: &AllocationSlotDescriptor,
36    ) -> Result<(), Self::Error>;
37}