|
| 1 | +use std::collections::HashMap; |
| 2 | + |
| 3 | +use super::{ |
| 4 | + RustVisibility, |
| 5 | + attr::RustAttribute, |
| 6 | + callable::RustCallable, |
| 7 | + renum::RustEnum, |
| 8 | + rimpl::RustImpl, |
| 9 | + rmacro::RustMacro, |
| 10 | + rstruct::RustStruct, |
| 11 | + rtrait::RustTrait, |
| 12 | + rtype::{RustType, RustTypeAlias}, |
| 13 | + variables::RustVariableDeclaration, |
| 14 | +}; |
| 15 | + |
| 16 | +/// Represents a Rust module with all possible items. |
| 17 | +#[derive(Debug, Clone, PartialEq, Eq)] |
| 18 | +pub struct RustModule { |
| 19 | + /// The name of the module. |
| 20 | + pub name: String, |
| 21 | + /// Documentation comment for the module. |
| 22 | + pub doc_comment: Option<String>, |
| 23 | + /// Attributes applied to the module. |
| 24 | + pub attributes: Vec<RustAttribute>, |
| 25 | + /// Visibility of the module. |
| 26 | + pub visibility: RustVisibility, |
| 27 | + |
| 28 | + // Type definitions |
| 29 | + /// Map of type definitions. |
| 30 | + pub types: HashMap<String, RustType>, |
| 31 | + /// Map of structs. |
| 32 | + pub structs: HashMap<String, RustStruct>, |
| 33 | + /// Map of enums. |
| 34 | + pub enums: HashMap<String, RustEnum>, |
| 35 | + /// Map of traits. |
| 36 | + pub traits: HashMap<String, RustTrait>, |
| 37 | + /// List of implementations. |
| 38 | + pub impls: Vec<RustImpl>, |
| 39 | + /// Map of type aliases. |
| 40 | + pub type_aliases: HashMap<String, RustTypeAlias>, |
| 41 | + |
| 42 | + // Functions and macros |
| 43 | + /// Map of functions. |
| 44 | + pub functions: HashMap<String, RustCallable>, |
| 45 | + /// Map of safe functions. |
| 46 | + pub safe_functions: HashMap<String, RustCallable>, |
| 47 | + /// Map of unsafe functions. |
| 48 | + pub unsafe_functions: HashMap<String, RustCallable>, |
| 49 | + /// Map of macros. |
| 50 | + pub macros: HashMap<String, RustMacro>, |
| 51 | + |
| 52 | + // Module structure |
| 53 | + /// Map of submodules. |
| 54 | + pub submodules: HashMap<String, RustModule>, |
| 55 | + /// Constants declared in the module. |
| 56 | + pub constants: Vec<RustVariableDeclaration>, |
| 57 | + /// List of use declarations. |
| 58 | + pub use_declarations: Vec<String>, |
| 59 | + /// List of extern crate declarations. |
| 60 | + pub extern_crates: Vec<String>, |
| 61 | + |
| 62 | + // Module properties |
| 63 | + /// Indicates if the module is marked as unsafe. |
| 64 | + pub is_unsafe: bool, |
| 65 | + /// The file path of the module. |
| 66 | + pub file_path: Option<String>, |
| 67 | + /// True if the file is named mod.rs. |
| 68 | + pub is_mod_rs: bool, |
| 69 | + /// True if this is the root module. |
| 70 | + pub is_root_module: bool, |
| 71 | +} |
| 72 | + |
| 73 | +impl RustModule { |
| 74 | + /// Creates a new `RustModule` with the given name. |
| 75 | + pub fn new(name: String) -> Self { |
| 76 | + Self { |
| 77 | + name, |
| 78 | + doc_comment: None, |
| 79 | + attributes: Vec::new(), |
| 80 | + visibility: RustVisibility::Private, |
| 81 | + types: HashMap::new(), |
| 82 | + structs: HashMap::new(), |
| 83 | + enums: HashMap::new(), |
| 84 | + traits: HashMap::new(), |
| 85 | + impls: Vec::new(), |
| 86 | + type_aliases: HashMap::new(), |
| 87 | + functions: HashMap::new(), |
| 88 | + safe_functions: HashMap::new(), |
| 89 | + unsafe_functions: HashMap::new(), |
| 90 | + macros: HashMap::new(), |
| 91 | + submodules: HashMap::new(), |
| 92 | + constants: Vec::new(), |
| 93 | + use_declarations: Vec::new(), |
| 94 | + extern_crates: Vec::new(), |
| 95 | + is_unsafe: false, |
| 96 | + file_path: None, |
| 97 | + is_mod_rs: false, |
| 98 | + is_root_module: false, |
| 99 | + } |
| 100 | + } |
| 101 | +} |
0 commit comments