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), and keepsfn main(the entry point must stay at the root); - 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; - a body-carrying
mod(e.g. the test module) of any size is extracted whole to its own file — its attributes (#[cfg(test)]must keep gating it) and visibility travel to the root declaration, and itssuper::*keeps pointing at the root; one over the ceiling is split further into a{name}/subdirectory.
Residual import/visibility that this mechanical scheme misses is left for the compiler to enumerate (the documented O(n) finish) — but the LOC budget and the byte-exact moves are done here.
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), elsepub(crate) use.
Functions§
- reassemble_
bin - Reassemble a binary crate-root split (back-compat wrapper).
- split_
bin - Plan and reassemble a binary crate-root split so that every output file is
< max_loc. 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 so every output file is
< max_loc; sub-modules see each other viasuper::*. 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.