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.
7pub trait AllocationPolicy {
8 /// Policy error type.
9 type Error;
10
11 /// Validate a stable key against framework naming rules.
12 fn validate_key(&self, key: &StableKey) -> Result<(), Self::Error>;
13
14 /// Validate a stable-key to allocation-slot claim.
15 fn validate_slot(
16 &self,
17 key: &StableKey,
18 slot: &AllocationSlotDescriptor,
19 ) -> Result<(), Self::Error>;
20
21 /// Validate a reserved stable-key to allocation-slot claim.
22 fn validate_reserved_slot(
23 &self,
24 key: &StableKey,
25 slot: &AllocationSlotDescriptor,
26 ) -> Result<(), Self::Error>;
27}
28
29///
30/// NamespaceAuthority
31///
32/// Policy-owned stable-key namespace ownership.
33pub trait NamespaceAuthority {
34 /// Return true when this authority owns `key`.
35 fn owns(&self, key: &StableKey) -> bool;
36}
37
38///
39/// RangeAuthority
40///
41/// Optional substrate-specific range authority validation.
42pub trait RangeAuthority {
43 /// Range validation error type.
44 type Error;
45
46 /// Validate one allocation slot against the authority.
47 fn validate_slot(&self, slot: &AllocationSlotDescriptor) -> Result<(), Self::Error>;
48}