Skip to main content

interstice_abi/schema/
node.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{ModuleSchema, ModuleVisibility};
4
5#[derive(Debug, Clone, Deserialize, Serialize)]
6pub struct NodeSchema {
7    pub name: String,
8    pub address: String,
9    pub modules: Vec<ModuleSchema>,
10}
11
12impl NodeSchema {
13    pub fn to_public(self) -> Self {
14        let mut modules = Vec::new();
15        for module in self.modules {
16            if module.visibility == ModuleVisibility::Public {
17                modules.push(module.to_public());
18            }
19        }
20        Self {
21            name: self.name,
22            address: self.address,
23            modules,
24        }
25    }
26
27    pub fn from_toml_string(toml_string: &str) -> Result<Self, toml::de::Error> {
28        toml::from_str(toml_string)
29    }
30
31    pub fn to_toml_string(&self) -> Result<String, toml::ser::Error> {
32        toml::to_string(&self)
33    }
34}