icydb_schema/node/
canister.rs1use crate::prelude::*;
2
3#[derive(CandidType, Clone, Debug, Serialize)]
8pub struct Canister {
9 pub def: Def,
10 pub memory_min: u8,
11 pub memory_max: u8,
12}
13
14impl MacroNode for Canister {
15 fn as_any(&self) -> &dyn std::any::Any {
16 self
17 }
18}
19
20impl ValidateNode for Canister {
21 fn validate(&self) -> Result<(), ErrorTree> {
22 let mut errs = ErrorTree::new();
23 let schema = schema_read();
24
25 let canister_path = self.def.path();
27 let mut seen_ids = std::collections::HashSet::new();
28 for (_, store) in schema.filter_nodes::<Store>(|node| node.canister == canister_path) {
29 let memory_id = store.memory_id;
30 if !seen_ids.insert(memory_id) {
31 err!(
32 errs,
33 "duplicate memory_id `{}` used in canister `{}`",
34 memory_id,
35 canister_path
36 );
37 }
38 }
39
40 if self.memory_min > self.memory_max {
42 err!(errs, "memory_min must be equal to or less than memory_max");
43 }
44
45 errs.result()
46 }
47}
48
49impl VisitableNode for Canister {
50 fn route_key(&self) -> String {
51 self.def.path()
52 }
53}