Skip to main content

Module generator

Module generator 

Source
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 nested mod {} blocks
  • MultiFileGenerator: 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§

GeneratedFiles
Result of multi-file generation.
GeneratedSource
Result of source generation.
ModuleTree
A hierarchical module tree for source generation.
MultiFileGenerator
Generator that outputs code into multiple files.
SingleFileGenerator
Generator that outputs all code into a single file.

Traits§

SourceGenerator
Trait for source code generators.