Skip to main content

RegistryGenerator

Struct RegistryGenerator 

Source
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 nested mod { } blocks
  • Multi-file mode (multi_file()): Each module gets its own .rs file
  • Multi-file mod.rs (multi_file_mod_rs()): Legacy mod.rs style instead of module.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: bool

Generate single file with nested mods (true) or multi-file (false)

§use_mod_rs: bool

Use mod.rs style (legacy) vs module.rs style (modern) for multi-file

Implementations§

Source§

impl RegistryGenerator

Source

pub fn single_file() -> Self

Create a new generator with single-file output.

Source

pub fn multi_file() -> Self

Create a new generator with multi-file output (modern style).

Source

pub fn multi_file_mod_rs() -> Self

Create a new generator with multi-file output (mod.rs style).

Source

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.

Source

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
  1. Collect affected modules from modified symbols
  2. Determine file paths based on CrateLayout (bin-only/lib/mixed)
  3. Generate only the affected files
§Arguments
  • ast_registry - The AST registry containing all symbols
  • symbol_registry - The symbol registry with path information
  • modified_symbols - SymbolIds that were modified during mutation
  • metadata - 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 files

Generate 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:

  1. to_source() (prettyplease) is O(file_size) per file
  2. Regenerating unmodified files causes format drift (vec![]vec!(), shorthand expansion, etc.)
  3. Writing unmodified files wastes I/O and triggers re-indexing

If modified_symbols is empty, returns an empty workspace immediately.

Source

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 hierarchy
  • ast_registry - The AST registry containing symbol ASTs
  • symbol_registry - The symbol registry with path information

Trait Implementations§

Source§

impl Clone for RegistryGenerator

Source§

fn clone(&self) -> RegistryGenerator

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RegistryGenerator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RegistryGenerator

Source§

fn default() -> RegistryGenerator

Returns the “default value” for a type. Read more
Source§

impl SourceGenerator for RegistryGenerator

Source§

fn generate( &self, ast_registry: &ASTRegistry, symbol_registry: &SymbolRegistry, ) -> Result<GeneratedWorkspace, ToSynError>

Generate source files from registries. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more