Skip to main content

icydb_schema/node/
def.rs

1use crate::prelude::*;
2
3///
4/// Def
5///
6
7#[derive(CandidType, Clone, Debug, Serialize)]
8pub struct Def {
9    module_path: &'static str,
10    ident: &'static str,
11    comments: Option<&'static str>,
12}
13
14impl Def {
15    /// Build one schema-definition identity triple.
16    #[must_use]
17    pub const fn new(
18        module_path: &'static str,
19        ident: &'static str,
20        comments: Option<&'static str>,
21    ) -> Self {
22        Self {
23            module_path,
24            ident,
25            comments,
26        }
27    }
28
29    /// Borrow definition module path.
30    #[must_use]
31    pub const fn module_path(&self) -> &'static str {
32        self.module_path
33    }
34
35    /// Borrow definition identifier.
36    #[must_use]
37    pub const fn ident(&self) -> &'static str {
38        self.ident
39    }
40
41    /// Borrow optional definition comments.
42    #[must_use]
43    pub const fn comments(&self) -> Option<&'static str> {
44        self.comments
45    }
46
47    // path
48    // the path to the actual Type
49    // ie. design::game::Rarity
50    #[must_use]
51    pub fn path(&self) -> String {
52        format!("{}::{}", self.module_path(), self.ident())
53    }
54}
55
56impl ValidateNode for Def {}
57
58impl VisitableNode for Def {}