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