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, and this policy receives external declarations only.
15/// The internal allocation-ledger declaration remains exclusively governed by
16/// ic-memory. Framework adapters should decide whether registered range claims
17/// or their own policy is authoritative for application ID space, then register
18/// ranges accordingly.
19///
20
21pub trait AllocationPolicy {
22 /// Policy error type.
23 type Error;
24
25 /// Validate a stable key against framework naming rules.
26 fn validate_key(&self, key: &StableKey) -> Result<(), Self::Error>;
27
28 /// Validate a stable-key to allocation-slot claim.
29 fn validate_slot(
30 &self,
31 key: &StableKey,
32 slot: &AllocationSlotDescriptor,
33 ) -> Result<(), Self::Error>;
34
35 /// Validate a reserved stable-key to allocation-slot claim.
36 fn validate_reserved_slot(
37 &self,
38 key: &StableKey,
39 slot: &AllocationSlotDescriptor,
40 ) -> Result<(), Self::Error>;
41}