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.
12pub trait AllocationPolicy {
13    /// Policy error type.
14    type Error;
15
16    /// Validate a stable key against framework naming rules.
17    fn validate_key(&self, key: &StableKey) -> Result<(), Self::Error>;
18
19    /// Validate a stable-key to allocation-slot claim.
20    fn validate_slot(
21        &self,
22        key: &StableKey,
23        slot: &AllocationSlotDescriptor,
24    ) -> Result<(), Self::Error>;
25
26    /// Validate a reserved stable-key to allocation-slot claim.
27    fn validate_reserved_slot(
28        &self,
29        key: &StableKey,
30        slot: &AllocationSlotDescriptor,
31    ) -> Result<(), Self::Error>;
32}