pub struct RegistryGenerator {
pub single_file: bool,
pub use_mod_rs: bool,
}Expand description
Generator that creates source files from ASTRegistry + SymbolRegistry.
Derives file structure purely from SymbolPath hierarchy - no existing files or span information required. This enables:
- Fresh file generation from scratch
- Module addition/removal without span manipulation
- Consistent output regardless of original file layout
§Output Format
The generator outputs GeneratedWorkspace containing crate-relative paths
(e.g., "src/lib.rs"). It does NOT handle workspace layout concerns like
where each crate lives within the workspace (e.g., "crates/core/src/lib.rs").
§Generation Modes
- Single-file mode (
single_file()): All symbols in one file with nestedmod { }blocks - Multi-file mode (
multi_file()): Each module gets its own.rsfile - Multi-file mod.rs (
multi_file_mod_rs()): Legacymod.rsstyle instead ofmodule.rs
§Example
let generator = RegistryGenerator::multi_file();
let workspace = generator.generate(&ast_registry, &symbol_registry);
// For symbols: core::Config, core::models::User
// Output: {"src/lib.rs": "...", "src/models.rs": "..."}Fields§
§single_file: boolGenerate single file with nested mods (true) or multi-file (false)
use_mod_rs: boolUse mod.rs style (legacy) vs module.rs style (modern) for multi-file
Implementations§
Source§impl RegistryGenerator
impl RegistryGenerator
Sourcepub fn single_file() -> Self
pub fn single_file() -> Self
Create a new generator with single-file output.
Sourcepub fn multi_file() -> Self
pub fn multi_file() -> Self
Create a new generator with multi-file output (modern style).
Sourcepub fn multi_file_mod_rs() -> Self
pub fn multi_file_mod_rs() -> Self
Create a new generator with multi-file output (mod.rs style).
Sourcepub fn generate(
&self,
ast_registry: &ASTRegistry,
symbol_registry: &SymbolRegistry,
) -> Result<GeneratedWorkspace, ToSynError>
pub fn generate( &self, ast_registry: &ASTRegistry, symbol_registry: &SymbolRegistry, ) -> Result<GeneratedWorkspace, ToSynError>
Generate source files from registries.
Handles both library symbols (crate::Foo) and binary symbols (main::crate::Foo).
Binary symbols are output to src/main.rs while library symbols go to src/lib.rs.
Sourcepub fn generate_affected(
&self,
ast_registry: &ASTRegistry,
symbol_registry: &SymbolRegistry,
modified_symbols: &[SymbolId],
_metadata: &CargoMetadataProvider,
) -> Result<GeneratedWorkspace, ToSynError>
pub fn generate_affected( &self, ast_registry: &ASTRegistry, symbol_registry: &SymbolRegistry, modified_symbols: &[SymbolId], _metadata: &CargoMetadataProvider, ) -> Result<GeneratedWorkspace, ToSynError>
Generate only files affected by modified symbols.
This method determines which files need regeneration based on the modified symbols and the generator’s file layout strategy (CrateLayout-aware).
§Strategy
- Collect affected modules from modified symbols
- Determine file paths based on CrateLayout (bin-only/lib/mixed)
- Generate only the affected files
§Arguments
ast_registry- The AST registry containing all symbolssymbol_registry- The symbol registry with path informationmodified_symbols- SymbolIds that were modified during mutationmetadata- Cargo metadata for CrateInfo lookup
§Returns
A GeneratedWorkspace containing only the affected files with crate-relative paths.
§Example
let modified = vec![status_id, todo_item_id];
let workspace = generator.generate_affected(
&ast_registry,
&symbol_registry,
&modified,
&metadata,
);
// workspace.crates["my_crate"].files contains only affected filesGenerate only files affected by modified symbols.
Maps each modified SymbolId to its crate-relative file path, then runs
the full organization phase (fast: HashMap grouping) but only serializes
affected files via to_source() (expensive: prettyplease).
§DESIGN INVARIANT
Full-workspace serialization is PROHIBITED. Only files containing modified symbols may be serialized. This is critical because:
to_source()(prettyplease) is O(file_size) per file- Regenerating unmodified files causes format drift
(
vec![]→vec!(), shorthand expansion, etc.) - Writing unmodified files wastes I/O and triggers re-indexing
If modified_symbols is empty, returns an empty workspace immediately.
Sourcepub fn generate_with_graph(
&self,
code_graph: &CodeGraphV2,
ast_registry: &ASTRegistry,
symbol_registry: &SymbolRegistry,
) -> Result<GeneratedWorkspace, ToSynError>
pub fn generate_with_graph( &self, code_graph: &CodeGraphV2, ast_registry: &ASTRegistry, symbol_registry: &SymbolRegistry, ) -> Result<GeneratedWorkspace, ToSynError>
Generate source files using CodeGraphV2 for module traversal.
This version uses the Contains edges in CodeGraphV2 to traverse the module hierarchy instead of re-grouping symbols with HashMaps. This provides O(1) child lookup per symbol instead of O(N) HashMap grouping.
§Arguments
code_graph- The code graph with Contains edges representing module hierarchyast_registry- The AST registry containing symbol ASTssymbol_registry- The symbol registry with path information
Trait Implementations§
Source§impl Clone for RegistryGenerator
impl Clone for RegistryGenerator
Source§fn clone(&self) -> RegistryGenerator
fn clone(&self) -> RegistryGenerator
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RegistryGenerator
impl Debug for RegistryGenerator
Source§impl Default for RegistryGenerator
impl Default for RegistryGenerator
Source§fn default() -> RegistryGenerator
fn default() -> RegistryGenerator
Source§impl SourceGenerator for RegistryGenerator
impl SourceGenerator for RegistryGenerator
Source§fn generate(
&self,
ast_registry: &ASTRegistry,
symbol_registry: &SymbolRegistry,
) -> Result<GeneratedWorkspace, ToSynError>
fn generate( &self, ast_registry: &ASTRegistry, symbol_registry: &SymbolRegistry, ) -> Result<GeneratedWorkspace, ToSynError>
Auto Trait Implementations§
impl Freeze for RegistryGenerator
impl RefUnwindSafe for RegistryGenerator
impl Send for RegistryGenerator
impl Sync for RegistryGenerator
impl Unpin for RegistryGenerator
impl UnsafeUnpin for RegistryGenerator
impl UnwindSafe for RegistryGenerator
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more