Skip to main content

icydb_schema/node/
newtype.rs

1use crate::prelude::*;
2
3///
4/// Newtype
5///
6
7#[derive(Clone, Debug, Serialize)]
8pub struct Newtype {
9    def: Def,
10    item: Item,
11
12    #[serde(skip_serializing_if = "Option::is_none")]
13    default: Option<Arg>,
14
15    ty: Type,
16}
17
18impl Newtype {
19    /// Creates a newtype node from its canonical schema parts.
20    #[must_use]
21    pub const fn new(def: Def, item: Item, default: Option<Arg>, ty: Type) -> Self {
22        Self {
23            def,
24            item,
25            default,
26            ty,
27        }
28    }
29
30    /// Returns the definition metadata for this newtype node.
31    #[must_use]
32    pub const fn def(&self) -> &Def {
33        &self.def
34    }
35
36    /// Returns the wrapped item descriptor.
37    #[must_use]
38    pub const fn item(&self) -> &Item {
39        &self.item
40    }
41
42    /// Returns the optional default value descriptor.
43    #[must_use]
44    pub const fn default(&self) -> Option<&Arg> {
45        self.default.as_ref()
46    }
47
48    /// Returns the canonical runtime type descriptor.
49    #[must_use]
50    pub const fn ty(&self) -> &Type {
51        &self.ty
52    }
53}
54
55impl MacroNode for Newtype {
56    fn as_any(&self) -> &dyn std::any::Any {
57        self
58    }
59}
60
61impl ValidateNode for Newtype {}
62
63impl VisitableNode for Newtype {
64    fn route_key(&self) -> String {
65        self.def().path()
66    }
67
68    fn drive<V: Visitor>(&self, v: &mut V) {
69        self.def().accept(v);
70        self.item().accept(v);
71        if let Some(node) = self.default() {
72            node.accept(v);
73        }
74        self.ty().accept(v);
75    }
76}