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