Skip to main content

ic_storage/
adapter.rs

1//! Supported upstream collections with governed memory and an explicit API.
2//!
3//! Constructors preserve upstream initialization, panic and persisted-format
4//! contracts. These wrappers expose neither raw memory nor unrestricted
5//! upstream collections.
6//! Use distinct admitted allocations for owning collections. Region views retain
7//! a shared lease for disjoint application frames and reload roots per operation.
8//! Drop collections and all shared lease owners before reopening.
9//! IC Memory enforces one live lease per allocation within each runtime;
10//! hosts retain exclusive custody of the backing across runtimes.
11use crate::substrate::{self, DefaultMemoryImpl};
12use ic_memory::RuntimeMemory;
13/// Exact substrate interfaces for backing bounds and record codecs.
14/// Implementing `Memory` grants no allocation authority; constructors require
15/// committed `RuntimeMemory` leases.
16pub use substrate::{Memory, Storable, storable, storable::Bound};
17
18#[cfg(all(test, not(target_arch = "wasm32")))]
19mod tests;
20
21mod region;
22pub use region::{BTreeMapRegion, RegionGrowError};
23
24mod map;
25pub use map::StableBTreeMap;
26mod set;
27pub use set::StableBTreeSet;
28mod cell;
29pub use cell::StableCell;
30mod vector;
31pub use vector::StableVec;
32mod heap;
33pub use heap::StableMinHeap;
34mod log;
35pub use log::StableLog;
36
37/// Upstream map iterator with governed memory.
38pub type MapIter<'a, K, V, M = DefaultMemoryImpl> =
39    substrate::btreemap::Iter<'a, K, V, RuntimeMemory<M>>;
40/// Upstream set iterator with governed memory.
41pub type SetIter<'a, K, M = DefaultMemoryImpl> = substrate::btreeset::Iter<'a, K, RuntimeMemory<M>>;
42/// Upstream log iterator with governed index and data memories.
43pub type LogIter<'a, T, M = DefaultMemoryImpl> =
44    substrate::log::Iter<'a, T, RuntimeMemory<M>, RuntimeMemory<M>>;
45
46pub use substrate::log::WriteError as LogWriteError;