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