Expand description
Source code generation from Pure AST.
This module provides generators that convert Pure AST structures into Rust source code. Different generators support different output strategies:
SingleFileGenerator: Generates a single lib.rs/main.rs with nestedmod {}blocksMultiFileGenerator: Generates multiple files following Rust module conventions
§Architecture
ModuleTree ──► SingleFileGenerator ──► PureFile ──► String (source code)
│
├── Hierarchical module structure with items
│
└─► MultiFileGenerator ──► GeneratedFiles (PathBuf → GeneratedSource)§Example
ⓘ
use ryo_source::generator::{ModuleTree, SingleFileGenerator, MultiFileGenerator};
let tree = ModuleTree::new("crate")
.with_item(PureItem::Struct(my_struct))
.with_child(ModuleTree::new("utils")
.with_item(PureItem::Fn(helper_fn)));
// Single file output
let generator = SingleFileGenerator::new();
let source = generator.generate(&tree);
// Multi-file output
let generator = MultiFileGenerator::new();
let files = generator.generate(&tree);
// files.get("lib.rs"), files.get("utils.rs"), etc.Structs§
- Generated
Files - Result of multi-file generation.
- Generated
Source - Result of source generation.
- Module
Tree - A hierarchical module tree for source generation.
- Multi
File Generator - Generator that outputs code into multiple files.
- Single
File Generator - Generator that outputs all code into a single file.
Traits§
- Source
Generator - Trait for source code generators.