| name | module-setup |
| description | Create or reorganize Rust modules following the remu Module Declaration Constitution. Use when adding a new .rs file, moving files, or fixing bare mod violations. |
Module Declaration Constitution (from AGENTS.md)
Every crate MUST declare its modules exclusively through remu_macro macros. Manual mod / pub mod / pub use for module plumbing is forbidden.
| Directory shape | Macro | Generated code |
|---|
src/X.rs (same-dir file) | mod_flat!(X) | mod X; pub use X::*; |
src/X/mod.rs (sub-dir) | mod_pub!(X) | pub mod X; |
src/X.rs (file, needs path access) | mod_pub_flat!(X) | pub mod X; pub use X::*; |
Rules
- Single-call-per-type: Each macro (
mod_flat!, mod_pub!, mod_pub_flat!) appears at most once per file. Merge same-type calls.
- Different types can coexist: One
mod_flat! + one mod_pub! is fine.
- Inline modules exempt:
mod func3 { ... }, mod tests { ... } don't need macros.
as alias exception: pub use LongName as Short; is OK after mod_pub!.
- Selective re-exports: Control visibility inside the module with
pub/pub(crate); mod_flat! exports only pub items.
Workflow
Adding a new same-directory file
- Create
src/new_file.rs
- Find the existing
mod_flat! call in lib.rs (or mod.rs for sub-modules)
- Add the new name to the list
- If no
mod_flat! exists yet, create one: remu_macro::mod_flat!(new_file);
Adding a new sub-directory module
- Create
src/new_module/mod.rs
- Find the existing
mod_pub! call
- Add the new name
- If no
mod_pub! exists, create one: remu_macro::mod_pub!(new_module);
Adding a file that needs both path access and flat export (e.g., prelude)
- Create
src/prelude.rs
- Use
remu_macro::mod_pub_flat!(prelude); — this replaces both pub mod prelude; and pub use prelude::*;
Common mistakes to catch
- Using
mod_pub! for same-directory files → should be mod_flat!
- Bare
mod X; without macro → violation
- Separate
pub use X::*; when mod_flat! already does it → redundant
- Two
mod_flat! calls instead of one merged call → violation of single-call-per-type
Exception
remu_macro/src/lib.rs uses bare mod module; mod pattern; — this is the ONLY allowed exception (bootstrap problem: the macros are defined inside those modules).