icydb_schema/node/
store.rs1use crate::prelude::*;
2use canic_core::utils::case::{Case, Casing};
3
4#[derive(Clone, Debug, Serialize)]
11pub struct Store {
12 pub def: Def,
13 pub ident: &'static str,
14 pub ty: StoreType,
15 pub canister: &'static str,
16 pub memory_id: u8,
17}
18
19impl MacroNode for Store {
20 fn as_any(&self) -> &dyn std::any::Any {
21 self
22 }
23}
24
25impl ValidateNode for Store {
26 fn validate(&self) -> Result<(), ErrorTree> {
27 let mut errs = ErrorTree::new();
28 let schema = schema_read();
29
30 match schema.cast_node::<Canister>(self.canister) {
32 Ok(canister) => {
33 if self.memory_id < canister.memory_min || self.memory_id > canister.memory_max {
34 err!(
35 errs,
36 "memory_id {} outside of range {}-{}",
37 self.memory_id,
38 canister.memory_min,
39 canister.memory_max,
40 );
41 }
42 }
43 Err(e) => errs.add(e),
44 }
45
46 if !self.ident.is_case(Case::UpperSnake) {
48 err!(errs, "ident '{}' must be UPPER_SNAKE_CASE", self.ident);
49 }
50
51 errs.result()
52 }
53}
54
55impl VisitableNode for Store {
56 fn route_key(&self) -> String {
57 self.def.path()
58 }
59
60 fn drive<V: Visitor>(&self, v: &mut V) {
61 self.def.accept(v);
62 }
63}