canic_core/model/memory/state/
subnet.rs1use crate::{
2 cdk::structures::{DefaultMemoryImpl, cell::Cell, memory::VirtualMemory},
3 eager_static, ic_memory, impl_storable_bounded,
4 model::memory::id::state::SUBNET_STATE_ID,
5};
6use candid::CandidType;
7use serde::{Deserialize, Serialize};
8use std::cell::RefCell;
9
10eager_static! {
16 static SUBNET_STATE: RefCell<Cell<SubnetStateData, VirtualMemory<DefaultMemoryImpl>>> =
17 RefCell::new(Cell::init(
18 ic_memory!(SubnetState, SUBNET_STATE_ID),
19 SubnetStateData::default(),
20 ));
21}
22
23#[derive(CandidType, Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
28pub struct SubnetStateData {}
29
30impl_storable_bounded!(SubnetStateData, 32, true);
31
32pub struct SubnetState;
37
38impl SubnetState {
39 pub fn import(data: SubnetStateData) {
40 SUBNET_STATE.with_borrow_mut(|cell| cell.set(data));
41 }
42
43 #[must_use]
44 pub fn export() -> SubnetStateData {
45 SUBNET_STATE.with_borrow(|cell| *cell.get())
46 }
47}