codebank/parser/
units.rs

1use super::{FileUnit, ModuleUnit, Visibility};
2use std::path::PathBuf;
3
4/// Implementation of ModuleUnit.
5///
6/// # Examples
7///
8/// ```
9/// use codebank::{ModuleUnit, Visibility};
10///
11/// // Create a new public module
12/// let module = ModuleUnit::new(
13///     "example".to_string(),
14///     Visibility::Public,
15///     Some("Module documentation".to_string()),
16/// );
17///
18/// assert_eq!(module.name, "example");
19/// assert!(matches!(module.visibility, Visibility::Public));
20/// assert_eq!(module.doc, Some("Module documentation".to_string()));
21/// assert!(module.functions.is_empty());
22/// assert!(module.structs.is_empty());
23/// assert!(module.traits.is_empty());
24/// assert!(module.impls.is_empty());
25/// assert!(module.submodules.is_empty());
26/// ```
27impl ModuleUnit {
28    /// Creates a new module unit with the given name, visibility, and documentation.
29    ///
30    /// # Arguments
31    ///
32    /// * `name` - The name of the module
33    /// * `visibility` - The visibility level of the module
34    /// * `document` - Optional documentation for the module
35    ///
36    /// # Examples
37    ///
38    /// ```
39    /// use codebank::{ModuleUnit, Visibility};
40    ///
41    /// let module = ModuleUnit::new(
42    ///     "my_module".to_string(),
43    ///     Visibility::Public,
44    ///     Some("Module docs".to_string()),
45    /// );
46    ///
47    /// assert_eq!(module.name, "my_module");
48    /// ```
49    pub fn new(name: String, visibility: Visibility, doc: Option<String>) -> Self {
50        Self {
51            name,
52            declares: Vec::new(),
53            visibility,
54            doc,
55            functions: Vec::new(),
56            structs: Vec::new(),
57            traits: Vec::new(),
58            impls: Vec::new(),
59            submodules: Vec::new(),
60            source: None,
61            attributes: Vec::new(),
62        }
63    }
64}
65
66/// Implementation of FileUnit.
67///
68/// # Examples
69///
70/// ```
71/// use std::path::PathBuf;
72/// use codebank::FileUnit;
73///
74/// // Create a new file unit
75/// let file = FileUnit::new(PathBuf::from("src/lib.rs"));
76///
77/// assert_eq!(file.path, PathBuf::from("src/lib.rs"));
78/// assert!(file.doc.is_none());
79/// assert!(file.declares.is_empty());
80/// assert!(file.modules.is_empty());
81/// assert!(file.functions.is_empty());
82/// assert!(file.structs.is_empty());
83/// assert!(file.traits.is_empty());
84/// assert!(file.impls.is_empty());
85/// assert!(file.source.is_none());
86/// ```
87impl FileUnit {
88    /// Creates a new file unit with the given path.
89    ///
90    /// # Arguments
91    ///
92    /// * `path` - The path to the file
93    ///
94    /// # Examples
95    ///
96    /// ```
97    /// use std::path::PathBuf;
98    /// use codebank::FileUnit;
99    ///
100    /// let file = FileUnit::new(PathBuf::from("src/main.rs"));
101    /// assert_eq!(file.path, PathBuf::from("src/main.rs"));
102    /// ```
103    pub fn new(path: PathBuf) -> Self {
104        Self {
105            path,
106            doc: None,
107            declares: Vec::new(),
108            modules: Vec::new(),
109            functions: Vec::new(),
110            structs: Vec::new(),
111            traits: Vec::new(),
112            impls: Vec::new(),
113            source: None,
114        }
115    }
116}