ic_memory/substrate.rs
1use crate::slot::AllocationSlotDescriptor;
2
3///
4/// LedgerAnchor
5///
6/// Substrate-defined location of the allocation ledger.
7#[derive(Clone, Debug, Eq, PartialEq)]
8pub struct LedgerAnchor {
9 /// Substrate identifier.
10 pub substrate: String,
11 /// Ledger storage descriptor.
12 pub descriptor: AllocationSlotDescriptor,
13}
14
15///
16/// StorageSubstrate
17///
18/// Physical storage provider for the ledger anchor and allocation slots.
19///
20/// A substrate knows how to open physical storage, but it should not decide
21/// allocation history on its own. Frameworks should validate and commit the
22/// ledger first, then open slots through [`crate::AllocationSession`].
23pub trait StorageSubstrate {
24 /// Native slot type accepted by this substrate.
25 type Slot;
26 /// Ledger memory handle.
27 type LedgerMemory;
28 /// Allocation memory handle.
29 type MemoryHandle;
30 /// Substrate error type.
31 type Error;
32
33 /// Open the ledger anchor.
34 fn open_ledger(&self) -> Result<Self::LedgerMemory, Self::Error>;
35
36 /// Open an allocation slot after validation has produced a session.
37 fn open_slot(&self, slot: &AllocationSlotDescriptor)
38 -> Result<Self::MemoryHandle, Self::Error>;
39
40 /// Describe a native slot as a durable allocation slot descriptor.
41 fn describe_slot(&self, slot: &Self::Slot) -> AllocationSlotDescriptor;
42}