1//! Data model for the analyzer
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
5/// Representation of a crate
6///
7/// .. req:: Represent a crate
8/// :id: RUST003
9/// :tags: rust
10/// :status: in-progress
11pub struct Crate {
12 pub name: String,
13 pub version: String,
14}
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
17/// Representation of a module
18///
19/// .. req:: Represent a module
20/// :id: RUST004
21/// :tags: rust
22/// :status: in-progress
23pub struct Module {
24 /// The path to the module file
25 pub file: Option<String>,
26 /// The fully qualified name of the module
27 pub path: Vec<String>,
28 pub docstring: String,
29 /// The public declarations in the module
30 pub declarations: Vec<String>,
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize)]
34/// Representation of a Struct
35///
36/// .. req:: Represent a struct
37/// :id: RUST005
38/// :tags: rust
39/// :status: in-progress
40pub struct Struct {
41 /// The fully qualified name of the struct
42 pub path: Vec<String>,
43 /// The docstring of the struct
44 pub docstring: String,
45 pub fields: Vec<Field>,
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize)]
49/// Representation of a Enum
50///
51/// .. req:: Represent an enum
52/// :id: RUST006
53/// :tags: rust
54/// :status: in-progress
55pub struct Enum {
56 /// The fully qualified name of the enum
57 pub path: Vec<String>,
58 /// The docstring of the enum
59 pub docstring: String,
60 pub variants: Vec<Variant>,
61}
62
63#[derive(Debug, Clone, Serialize, Deserialize)]
64/// Representation of a Enum variant
65pub struct Variant {
66 /// The fully qualified name of the variant
67 pub path: Vec<String>,
68 /// The docstring of the variant
69 pub docstring: String,
70 pub discriminant: Option<String>, // TODO shouldn't just be a string
71 pub fields: Vec<Field>,
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
75/// Representation of a Struct or Enum field
76pub struct Field {
77 /// The fully qualified name of the field.
78 ///
79 /// Note, for fields of tuple structs, the final component is the index of the field
80 pub path: Vec<String>,
81 /// The docstring of the field
82 pub docstring: String,
83 pub type_: TypeSignature,
84}
85
86#[derive(Debug, Clone, Serialize, Deserialize)]
87/// Representation of a function
88pub struct Function {
89 /// The fully qualified name of the function.
90 pub path: Vec<String>,
91 /// The docstring of the function
92 pub docstring: String,
93 // TODO signature
94}
95
96#[derive(Debug, Clone, Serialize, Deserialize)]
97/// A segment of a type signature
98///
99/// Types are split into segments to allow for easy identification of referenceable elements
100pub enum TypeSegment {
101 String(String),
102 Path(String),
103}
104
105/// A representation of a type signature
106pub type TypeSignature = Vec<TypeSegment>;