pub struct ModuleTree {
pub name: String,
pub vis: PureVis,
pub uses: Vec<PureUse>,
pub inner_attrs: Vec<PureAttribute>,
pub items: Vec<PureItem>,
pub children: Vec<ModuleTree>,
}Expand description
A hierarchical module tree for source generation.
This structure represents a complete module hierarchy that can be
transformed into source code by a SourceGenerator.
§Example
// Build a tree representing:
// mod utils {
// use std::io;
// pub fn helper() {}
// }
let tree = ModuleTree::new("utils")
.with_vis(PureVis::Public)
.with_use(PureUse { ... })
.with_item(PureItem::Fn(helper_fn));Fields§
§name: StringModule name (empty string for crate root).
vis: PureVisModule visibility.
uses: Vec<PureUse>Use statements for this module.
inner_attrs: Vec<PureAttribute>Inner attributes (e.g., //! doc, #![allow(...)]).
items: Vec<PureItem>Items in this module (structs, functions, etc.).
children: Vec<ModuleTree>Child modules.
Implementations§
Source§impl ModuleTree
impl ModuleTree
Sourcepub fn new(name: impl Into<String>) -> Self
pub fn new(name: impl Into<String>) -> Self
Create a new module tree with the given name.
For crate root, use an empty string or “crate”.
Sourcepub fn crate_root() -> Self
pub fn crate_root() -> Self
Create a crate root module tree.
Sourcepub fn with_uses(self, uses: impl IntoIterator<Item = PureUse>) -> Self
pub fn with_uses(self, uses: impl IntoIterator<Item = PureUse>) -> Self
Add multiple use statements.
Sourcepub fn with_inner_attr(self, attr: PureAttribute) -> Self
pub fn with_inner_attr(self, attr: PureAttribute) -> Self
Add an inner attribute.
Sourcepub fn with_items(self, items: impl IntoIterator<Item = PureItem>) -> Self
pub fn with_items(self, items: impl IntoIterator<Item = PureItem>) -> Self
Add multiple items.
Sourcepub fn with_child(self, child: ModuleTree) -> Self
pub fn with_child(self, child: ModuleTree) -> Self
Add a child module.
Sourcepub fn with_children(
self,
children: impl IntoIterator<Item = ModuleTree>,
) -> Self
pub fn with_children( self, children: impl IntoIterator<Item = ModuleTree>, ) -> Self
Add multiple child modules.
Sourcepub fn is_crate_root(&self) -> bool
pub fn is_crate_root(&self) -> bool
Check if this is the crate root.
Sourcepub fn total_items(&self) -> usize
pub fn total_items(&self) -> usize
Get total item count (including children).
Sourcepub fn total_modules(&self) -> usize
pub fn total_modules(&self) -> usize
Get total module count (including self and children).
Sourcepub fn find_child(&self, name: &str) -> Option<&ModuleTree>
pub fn find_child(&self, name: &str) -> Option<&ModuleTree>
Find a child module by name.
Sourcepub fn find_child_mut(&mut self, name: &str) -> Option<&mut ModuleTree>
pub fn find_child_mut(&mut self, name: &str) -> Option<&mut ModuleTree>
Find a child module by name (mutable).
Sourcepub fn get_or_create_child(&mut self, name: &str) -> &mut ModuleTree
pub fn get_or_create_child(&mut self, name: &str) -> &mut ModuleTree
Get or create a child module by name.
If a child with the given name exists, returns a mutable reference to it. Otherwise, creates a new child module and returns a mutable reference.
Navigate to a nested module by path.
Path is a slice of module names, e.g., ["foo", "bar"] for foo::bar.
Navigate to a nested module by path (mutable).
Sourcepub fn get_or_create_path(&mut self, path: &[&str]) -> &mut ModuleTree
pub fn get_or_create_path(&mut self, path: &[&str]) -> &mut ModuleTree
Get or create nested modules by path.
Creates any missing intermediate modules.
Trait Implementations§
Source§impl Clone for ModuleTree
impl Clone for ModuleTree
Source§fn clone(&self) -> ModuleTree
fn clone(&self) -> ModuleTree
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more