ic_storage/adapter.rs
1//! Governed collections with an explicit API.
2//!
3//! Storage owns every collection engine and its current format. Constructors
4//! enforce explicit creation and loading without exposing raw backing.
5//! Use distinct admitted allocations for owning collections. Region views retain
6//! a shared lease for disjoint application frames and reload roots per operation.
7//! Drop collections and all shared lease owners before reopening.
8//! Collection IO and codecs return typed errors for validation and capacity
9//! refusal. Backing panics/traps remain host failures; native writes are not atomic.
10//! Map and set iterators yield `Result` entries and stop after an iteration error.
11//! The allocation runtime enforces one live lease per allocation;
12//! hosts retain exclusive custody of the backing across runtimes.
13// Collection APIs require public documentation in addition to workspace Clippy.
14#![warn(clippy::all, clippy::pedantic, missing_docs)]
15use crate::DefaultMemoryImpl;
16use crate::RuntimeMemory;
17pub use crate::storable::{Bound, CodecError, Storable};
18/// Storage-owned interfaces for backing bounds and record codecs.
19/// Implementing `Memory` grants no allocation authority; constructors require
20/// committed `RuntimeMemory` leases.
21pub use crate::{Memory, storable};
22
23#[cfg(all(test, not(target_arch = "wasm32")))]
24mod tests;
25
26mod error;
27mod record;
28pub use error::CollectionError;
29mod tree;
30
31mod region;
32pub use region::{BTreeMapRegion, RegionGrowError};
33
34mod map;
35pub use map::StableBTreeMap;
36mod set;
37pub use set::StableBTreeSet;
38mod cell;
39pub use cell::StableCell;
40mod vector;
41pub use vector::StableVec;
42
43/// Ordered map iterator retaining the collection borrow.
44pub type MapIter<'a, K, V, M = DefaultMemoryImpl> = tree::TreeIter<'a, K, V, RuntimeMemory<M>>;
45pub use tree::MapEntry;
46/// Ordered set iterator retaining the collection borrow.
47pub type SetIter<'a, K, M = DefaultMemoryImpl> = set::SetIter<'a, K, M>;