pub struct FileUnit {
pub path: PathBuf,
pub document: Option<String>,
pub declares: Vec<DeclareStatements>,
pub modules: Vec<ModuleUnit>,
pub functions: Vec<FunctionUnit>,
pub structs: Vec<StructUnit>,
pub traits: Vec<TraitUnit>,
pub impls: Vec<ImplUnit>,
pub source: Option<String>,
}Expand description
Represents a file in the code.
This struct contains all the parsed information about a source code file, including its structure, contents, and metadata.
§Examples
use codebank::{FileUnit, Visibility, FunctionUnit};
use std::path::PathBuf;
// Create a new file unit
let mut file = FileUnit::new(PathBuf::from("example.rs"));
// Add documentation
file.document = Some("Example file documentation".to_string());
// Add a function
let function = FunctionUnit {
name: "example_function".to_string(),
visibility: Visibility::Public,
documentation: Some("Function documentation".to_string()),
signature: Some("fn example_function()".to_string()),
body: Some("{ println!(\"Hello\"); }".to_string()),
source: Some("fn example_function() { println!(\"Hello\"); }".to_string()),
attributes: vec![],
};
file.functions.push(function);
assert_eq!(file.path, PathBuf::from("example.rs"));
assert!(file.document.is_some());
assert!(!file.functions.is_empty());Fields§
§path: PathBufThe path to the file
document: Option<String>File-level documentation
declares: Vec<DeclareStatements>The declares in the file, e.g. imports, use statements, mod statements, c includes, python/js imports, etc.
modules: Vec<ModuleUnit>The modules contained in the file
functions: Vec<FunctionUnit>Top-level functions not in a module
structs: Vec<StructUnit>Top-level structs not in a module
traits: Vec<TraitUnit>Top-level traits not in a module
impls: Vec<ImplUnit>Top-level implementation blocks
source: Option<String>Source code of the entire file
Implementations§
Source§impl FileUnit
Implementation of FileUnit.
impl FileUnit
Implementation of FileUnit.
§Examples
use std::path::PathBuf;
use codebank::FileUnit;
// Create a new file unit
let file = FileUnit::new(PathBuf::from("src/lib.rs"));
assert_eq!(file.path, PathBuf::from("src/lib.rs"));
assert!(file.document.is_none());
assert!(file.declares.is_empty());
assert!(file.modules.is_empty());
assert!(file.functions.is_empty());
assert!(file.structs.is_empty());
assert!(file.traits.is_empty());
assert!(file.impls.is_empty());
assert!(file.source.is_none());Trait Implementations§
Auto Trait Implementations§
impl Freeze for FileUnit
impl RefUnwindSafe for FileUnit
impl Send for FileUnit
impl Sync for FileUnit
impl Unpin for FileUnit
impl UnwindSafe for FileUnit
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more