Expand description
Tier 2 step 2 — reassemble a planned split into output module files.
Target: a binary/crate-root file (e.g. src/main.rs) whose items all
live in one module and reference each other by bare name. Splitting them
into sibling modules breaks those bare references, so the scheme is:
- the crate root keeps the file preamble + imports, the source’s own
re-exports (
pub use ...— dropping or demoting one would narrow the crate’s public API) and content-lessmod name;declarations verbatim, declares each part module, re-exports each part with a single glob whose visibility matches the part’s widest item (pub usewhen the part has a public item, elsepub(crate) use, and nothing for animpl-only part), keeps local types with inherent impls verbatim (their private fields stay accessible to children), and keepsfn main(the entry point stays here); - each part file copies the imports it references by name (preamble stays at
the root), does
use crate::*to see its siblings via the root re-exports, and carries its items withpub(crate)visibility bumped on so the re-exports can see them; - unconditional body-carrying modules are extracted whole, with attributes and visibility on their declarations; large bodies are split recursively;
- conditional modules keep their braced boundaries inline, and oversized leaves stay intact in their original module. An unmet budget never justifies dropping a declaration.
Residual import/visibility that this mechanical scheme misses is left for the compiler to enumerate (the documented O(n) finish). Unmet LOC budgets are reported alongside the preserved output.
Structs§
- Output
File - A file the split would write.
- Split
Output - The reassembled output plus the parts of the plan that could not be met.
Enums§
- Topology
- How the split file sits in the module tree — fixes the sibling path prefix
and where sub-module files go. Re-export visibility is per part in both
topologies:
pub usewhen the part has a public item (preserving the crate’s public API), else no wider than the part’s items need.
Functions§
- reassemble_
bin - Reassemble a binary crate-root split (back-compat wrapper).
- split_
bin - Plan and reassemble a binary crate-root split targeting files
< max_loc. Indivisible items and conditional modules stay in their original scope; consultstill_oversizedandmax_loc()for unmet budget constraints. The item budget reserves the full header LOC and the per-part overhead; since a part now copies only the imports it references (a subset of the header), this reservation is conservative — a packed part stays safely under budget. - split_
mod - Plan and reassemble a library module targeting files
< max_loc; sub-modules see each other viasuper::*. Unmet budgets are reported without discarding declarations. Handles both a directory-owningfoo/mod.rs(sub-modules become siblings) and a plainfoo.rsfile module (sub-modules go in afoo/subdir).root_stemis the source file’s stem.