1use serde::{Deserialize, Serialize};
2
3pub const SCHEMA_VERSION: u32 = 12;
6
7#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
9#[serde(rename_all = "snake_case")]
10pub enum NodeKind {
11 Folder,
12 File,
13 Module,
14 Struct,
15 Enum,
16 Trait,
18 Interface,
20 TypeAlias,
21 Function,
22 Method,
23 Property,
25 Constant,
26 Macro,
27 Annotation,
29 EnumMember,
31 Section,
34}
35
36impl std::fmt::Display for NodeKind {
37 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
38 let s = match self {
39 NodeKind::Folder => "folder",
40 NodeKind::File => "file",
41 NodeKind::Module => "module",
42 NodeKind::Struct => "struct",
43 NodeKind::Enum => "enum",
44 NodeKind::Trait => "trait",
45 NodeKind::Interface => "interface",
46 NodeKind::TypeAlias => "type_alias",
47 NodeKind::Function => "function",
48 NodeKind::Method => "method",
49 NodeKind::Property => "property",
50 NodeKind::Constant => "constant",
51 NodeKind::Macro => "macro",
52 NodeKind::Annotation => "annotation",
53 NodeKind::EnumMember => "enum_member",
54 NodeKind::Section => "section",
55 };
56 f.write_str(s)
57 }
58}
59
60impl std::str::FromStr for NodeKind {
61 type Err = ();
62 fn from_str(s: &str) -> Result<Self, Self::Err> {
63 match s {
64 "folder" => Ok(NodeKind::Folder),
65 "file" => Ok(NodeKind::File),
66 "module" => Ok(NodeKind::Module),
67 "struct" => Ok(NodeKind::Struct),
68 "enum" => Ok(NodeKind::Enum),
69 "trait" => Ok(NodeKind::Trait),
70 "interface" => Ok(NodeKind::Interface),
71 "type_alias" => Ok(NodeKind::TypeAlias),
72 "function" => Ok(NodeKind::Function),
73 "method" => Ok(NodeKind::Method),
74 "property" => Ok(NodeKind::Property),
75 "constant" => Ok(NodeKind::Constant),
76 "macro" => Ok(NodeKind::Macro),
77 "annotation" => Ok(NodeKind::Annotation),
78 "enum_member" | "enum-member" => Ok(NodeKind::EnumMember),
79 "section" => Ok(NodeKind::Section),
80 _ => Err(()),
81 }
82 }
83}
84
85#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
87#[serde(rename_all = "snake_case")]
88pub enum EdgeKind {
89 Contains,
91 Calls,
93 Implements,
95 Inherits,
99 Uses,
101 Imports,
103 Annotated,
106 Throws,
108 References,
112}
113
114impl std::fmt::Display for EdgeKind {
115 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
116 let s = match self {
117 EdgeKind::Contains => "contains",
118 EdgeKind::Calls => "calls",
119 EdgeKind::Implements => "implements",
120 EdgeKind::Inherits => "inherits",
121 EdgeKind::Uses => "uses",
122 EdgeKind::Imports => "imports",
123 EdgeKind::Annotated => "annotated",
124 EdgeKind::Throws => "throws",
125 EdgeKind::References => "references",
126 };
127 f.write_str(s)
128 }
129}
130
131#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
136#[serde(rename_all = "snake_case")]
137pub enum EdgeConfidence {
138 #[default]
140 Extracted,
141 Inferred,
143}
144
145impl std::fmt::Display for EdgeConfidence {
146 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
147 f.write_str(match self {
148 EdgeConfidence::Extracted => "extracted",
149 EdgeConfidence::Inferred => "inferred",
150 })
151 }
152}
153
154impl EdgeConfidence {
155 pub fn from_label(s: &str) -> Self {
157 match s {
158 "inferred" => EdgeConfidence::Inferred,
159 _ => EdgeConfidence::Extracted,
160 }
161 }
162}
163
164#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
166#[serde(rename_all = "snake_case")]
167pub enum Visibility {
168 #[default]
169 Private,
170 PubCrate,
171 Pub,
172}
173
174impl std::fmt::Display for Visibility {
175 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
176 match self {
177 Visibility::Pub => f.write_str("pub"),
178 Visibility::PubCrate => f.write_str("pub_crate"),
179 Visibility::Private => f.write_str("private"),
180 }
181 }
182}
183
184impl std::str::FromStr for Visibility {
185 type Err = ();
186 fn from_str(s: &str) -> Result<Self, Self::Err> {
187 match s {
188 "pub" => Ok(Visibility::Pub),
189 "pub_crate" => Ok(Visibility::PubCrate),
190 "private" => Ok(Visibility::Private),
191 _ => Err(()),
192 }
193 }
194}
195
196#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
200#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
201pub enum SolidHint {
202 Srp,
204 Ocp,
206 Lsp,
208 Isp,
210 Dip,
212}
213
214#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
216#[serde(rename_all = "snake_case")]
217pub enum DesignPattern {
218 Builder,
219 Factory,
220 Observer,
221 Strategy,
222 Decorator,
223 Singleton,
224 Repository,
225}
226
227#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
229#[serde(rename_all = "snake_case")]
230pub enum CodeSmell {
231 GodStruct,
233 LongMethod,
235 DeepNesting,
237 FatInterface,
239}