|
| 1 | +use crate::entities::{RustVisibility, attr::RustAttribute, rtype::RustType}; |
| 2 | +/// Represents a variable declaration in Rust. |
| 3 | +/// |
| 4 | +/// # Fields |
| 5 | +/// |
| 6 | +/// * `name` - The name of the variable |
| 7 | +/// * `type_info` - Optional type information of the variable |
| 8 | +/// * `is_mut` - Flag indicating if the variable is mutable |
| 9 | +/// * `is_static` - Flag indicating if the variable is static |
| 10 | +/// * `is_const` - Flag indicating if the variable is a constant |
| 11 | +/// * `initializer` - Optional initialization expression as a string |
| 12 | +/// * `visibility` - Visibility level of the variable (public, private, etc.) |
| 13 | +/// * `doc_comment` - Optional documentation comment associated with the variable |
| 14 | +/// * `attributes` - Vector of attributes associated with the variable |
| 15 | +/// * `line_number` - Line number where the variable is declared in the source code |
| 16 | +/// |
| 17 | +/// # Examples |
| 18 | +/// |
| 19 | +/// ``` |
| 20 | +/// let var = RustVariableDeclaration::new(String::from("my_var"), 1); |
| 21 | +/// assert_eq!(var.name, "my_var"); |
| 22 | +/// assert_eq!(var.line_number, 1); |
| 23 | +/// ``` |
| 24 | +#[derive(Debug, Clone)] |
| 25 | +pub struct RustVariableDeclaration { |
| 26 | + /// The name of the variable |
| 27 | + pub name: String, |
| 28 | + /// The type of the variable (optional) |
| 29 | + pub type_info: Option<RustType>, |
| 30 | + /// Whether the variable is mutable |
| 31 | + pub is_mut: bool, |
| 32 | + /// Whether the variable is static |
| 33 | + pub is_static: bool, |
| 34 | + /// Whether the variable is const |
| 35 | + pub is_const: bool, |
| 36 | + /// The initializer expression (optional) |
| 37 | + pub initializer: Option<String>, |
| 38 | + /// The visibility of the variable |
| 39 | + pub visibility: RustVisibility, |
| 40 | + /// Documentation comment (optional) |
| 41 | + pub doc_comment: Option<String>, |
| 42 | + /// Associated attributes |
| 43 | + pub attributes: Vec<RustAttribute>, |
| 44 | + /// Line number in source code |
| 45 | + pub line_number: usize, |
| 46 | +} |
| 47 | + |
| 48 | +impl RustVariableDeclaration { |
| 49 | + pub fn new(name: String, line_number: usize) -> Self { |
| 50 | + Self { |
| 51 | + name, |
| 52 | + type_info: None, |
| 53 | + is_mut: false, |
| 54 | + is_static: false, |
| 55 | + is_const: false, |
| 56 | + initializer: None, |
| 57 | + visibility: RustVisibility::Private, |
| 58 | + doc_comment: None, |
| 59 | + attributes: Vec::new(), |
| 60 | + line_number, |
| 61 | + } |
| 62 | + } |
| 63 | +} |
0 commit comments