Rust: the root modules hold most of the code #356

Closed
opened 2026-10-23 18:00:04 -07:00 by rays · 1 comment
Owner

The style guide wants non-leaf modules (main.rs, lib.rs) to hold module declarations and re-exports, with the code in leaf modules named after what they hold. ipx's main.rs is 3,200 lines of logic (scans, OPML, catalogue, the daemon), ipx-feed's lib.rs 2,000 (fetching, parsing, OPML, Patreon, Jev), and db.rs 4,200 (2026-10-24).

The style guide wants non-leaf modules (main.rs, lib.rs) to hold module declarations and re-exports, with the code in leaf modules named after what they hold. ipx's main.rs is 3,200 lines of logic (scans, OPML, catalogue, the daemon), ipx-feed's lib.rs 2,000 (fetching, parsing, OPML, Patreon, Jev), and db.rs 4,200 (2026-10-24).
rays added the enhancement label 2026-10-23 18:00:04 -07:00
Author
Owner

Done, in three commits, all deployed:

  • 4f4fd4c: ipx's main.rs (3,200 lines) into cli, ctx, daemon, scan, catalogue, lists (OPML; not opml.rs, which would shadow the opml crate), logging and a test-only test_util; first_password went to auth.rs and reap to retention.rs. main.rs is now the module list and a 70-line main(). With Ctx no longer pub at the crate root, the compiler saw Db methods only tests call (now #[cfg(test)]) and one nothing called (media_feeds, removed).
  • ff5d786: ipx-feed's lib.rs (2,000 lines) into fetch, parse, outlines, patreon, discover, wordpress, failure, privacy, artwork, category and jev; lib.rs re-exports, so callers are unchanged.
  • ecff2f8: ipx-directory's lib.rs, a crate root with handlers in it though not named above, into wire, directory and api.

Each split was checked to keep every definition and doc comment line exactly once; tests went with what they test and all still run (ipx 151, feed 40, directory 23, browser 85). Log lines from the moved code now carry their module as target (ipx::daemon, ...); the dashboard and prod-check filter on explicit targets, which did not change.

db.rs stays one file: it is a leaf module named for its primary item, which the guide's rule is about root modules does not touch, and splitting it would make it a root module of its own.

Done, in three commits, all deployed: - 4f4fd4c: ipx's main.rs (3,200 lines) into cli, ctx, daemon, scan, catalogue, lists (OPML; not opml.rs, which would shadow the opml crate), logging and a test-only test_util; first_password went to auth.rs and reap to retention.rs. main.rs is now the module list and a 70-line main(). With Ctx no longer pub at the crate root, the compiler saw Db methods only tests call (now #[cfg(test)]) and one nothing called (media_feeds, removed). - ff5d786: ipx-feed's lib.rs (2,000 lines) into fetch, parse, outlines, patreon, discover, wordpress, failure, privacy, artwork, category and jev; lib.rs re-exports, so callers are unchanged. - ecff2f8: ipx-directory's lib.rs, a crate root with handlers in it though not named above, into wire, directory and api. Each split was checked to keep every definition and doc comment line exactly once; tests went with what they test and all still run (ipx 151, feed 40, directory 23, browser 85). Log lines from the moved code now carry their module as target (ipx::daemon, ...); the dashboard and prod-check filter on explicit targets, which did not change. db.rs stays one file: it is a leaf module named for its primary item, which the guide's rule is about root modules does not touch, and splitting it would make it a root module of its own.
rays closed this issue 2026-10-23 18:54:11 -07:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: rays/ipx#356