Skip to content

Split main.rs: 28k lines, a 1,700-line main() and an 86-field WorkerState #206

Closed

Description

@Sythos

crates/cordiale-ui/src/main.rs is 28,699 lines at v0.1.16. About 16,000 are production code and about 12,700 are the #[cfg(test)] module in the same file; appwindow.slint adds another 7,400.

Measured with a small script that matches braces (so roughly right, not exact):

  • 381 top-level functions; 12 longer than 100 lines and 6 longer than 200.
  • main: 1,710 lines. run_worker: 1,209. handle_frame: 639. run_slash_command: 459. finish_connect: 338. handle_admin_write: 206.
  • WorkerState: 86 fields in one struct that every handler takes as &mut.

Why it hurts: nearly every issue touches this file, so branches conflict constantly (the last round of merges needed main merged into each branch in turn); a one-line change recompiles and re-lints the whole crate; and a 1,200-line async loop is hard to reason about for ordering and cancellation.

The code already has the seams: home.rs, ceremony.rs, passkeys.rs, totp.rs, reply.rs, debug_info.rs, dates.rs are separate modules that came out well.

Proposal (no behaviour change, one small PR per step so the diffs stay reviewable and merge cleanly)

  1. Move the test module out of main.rs (a tests/ folder of per-area files next to the modules). That alone removes 12k lines from the file.
  2. Extract the frame dispatch (handle_frame and its per-kind handlers) into frames/.
  3. Extract slash commands, admin handlers, query windows, channel list and history into their own modules.
  4. Split WorkerState into a few sub-structs by area (connection, windows and history, settings caches, admin, presence), passed to the handlers that need them.
  5. Break main() into setup functions (callbacks per area), and run_worker into a command dispatcher plus handlers.

Do the steps while few branches are open, and keep cargo test green after each one.

Activity

  1. self-assigned this
    on Oct 2, 2026
  2. added
    enhancementNew feature or request
    Enya: CookingBeing worked on by Enya: don't pick it up in parallel
    on Oct 2, 2026
  3. added a commit that references this issue on Oct 2, 2026
  4. reopened this on Oct 2, 2026
  5. added 7 commits that reference this issue on Oct 2, 2026
  6. 4 remaining items

  7. added 12 commits that reference this issue on Oct 3, 2026
  8. removed
    Enya: CookingBeing worked on by Enya: don't pick it up in parallel
    on Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions