icydb_core/db/store/
data.rs1use crate::db::store::{DataKey, RawDataKey, RawRow, StoreRegistry};
2use canic_cdk::structures::{BTreeMap, DefaultMemoryImpl, memory::VirtualMemory};
3use derive_more::{Deref, DerefMut};
4
5pub type DataRow = (DataKey, RawRow);
10
11#[derive(Deref, DerefMut)]
16pub struct DataStoreRegistry(StoreRegistry<DataStore>);
17
18impl DataStoreRegistry {
19 #[must_use]
20 #[allow(clippy::new_without_default)]
21 pub fn new() -> Self {
23 Self(StoreRegistry::new())
24 }
25}
26
27#[derive(Deref, DerefMut)]
32pub struct DataStore(BTreeMap<RawDataKey, RawRow, VirtualMemory<DefaultMemoryImpl>>);
33
34impl DataStore {
35 #[must_use]
36 pub fn init(memory: VirtualMemory<DefaultMemoryImpl>) -> Self {
38 Self(BTreeMap::init(memory))
39 }
40
41 pub fn memory_bytes(&self) -> u64 {
43 self.iter()
44 .map(|entry| u64::from(DataKey::STORED_SIZE) + entry.value().len() as u64)
45 .sum()
46 }
47}