use ic_stable_structures::{BTreeMap, BTreeSet, Cell, MinHeap, Storable, Vec};
#[doc(hidden)]
pub trait StorageType {
type Type;
fn init(memory: crate::Memory) -> Self::Type;
}
pub struct StableBTreeMap<K: Storable + Ord + Clone, V: Storable> {
_phantom: std::marker::PhantomData<(K, V)>,
}
impl<K, V> StorageType for StableBTreeMap<K, V>
where
K: Storable + Ord + Clone,
V: Storable,
{
type Type = BTreeMap<K, V, crate::Memory>;
fn init(memory: crate::Memory) -> BTreeMap<K, V, crate::Memory> {
BTreeMap::init(memory)
}
}
pub struct StableCell<T: Storable> {
_phantom: std::marker::PhantomData<T>,
}
impl<T> StorageType for StableCell<T>
where
T: Storable,
{
type Type = Cell<Option<T>, crate::Memory>;
fn init(memory: crate::Memory) -> Cell<Option<T>, crate::Memory> {
Cell::init(memory, None)
}
}
pub struct StableBTreeSet<T: Storable + Ord + Clone> {
_phantom: std::marker::PhantomData<T>,
}
impl<T> StorageType for StableBTreeSet<T>
where
T: Storable + Ord + Clone,
{
type Type = BTreeSet<T, crate::Memory>;
fn init(memory: crate::Memory) -> BTreeSet<T, crate::Memory> {
BTreeSet::init(memory)
}
}
pub struct StableVec<T: Storable> {
_phantom: std::marker::PhantomData<T>,
}
impl<T> StorageType for StableVec<T>
where
T: Storable,
{
type Type = Vec<T, crate::Memory>;
fn init(memory: crate::Memory) -> Vec<T, crate::Memory> {
Vec::init(memory)
}
}
pub struct StableMinHeap<T: Storable + Ord + Clone> {
_phantom: std::marker::PhantomData<T>,
}
impl<T> StorageType for StableMinHeap<T>
where
T: Storable + Ord + Clone,
{
type Type = MinHeap<T, crate::Memory>;
fn init(memory: crate::Memory) -> MinHeap<T, crate::Memory> {
MinHeap::init(memory)
}
}