How to organize modules

⚓ Rust    📅 2026-03-29    👤 surdeus    👁️ 9      

surdeus

Info

This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: How to organize modules

Hi!

I'm working on a project, and I am struggling to find a module file structure that works for me personally. There's a module of services:

services/
services/auth/mod.rs, provider1.rs, .... [auth internals]
services/log/mod.rs, .. [log internals]
services/db/mod.rs, ... [db internals]

The issue is, I do not want to put any code into mod.rs because then I just have dozen mod.rs files opened which is very annoying. Yeah, my IDE sees that, and does auth/mod.rs, log/mod.rs, db/mod.rs as the tab name instead of just 3x mod.rs but it still feels annoying.

So I tend to put code into services/serviceName/serviceName.rs, ie

services/
services/auth/mod.rs, auth.rs, .... [auth internals]
services/log/mod.rs, log.rs, .. [log internals]
services/db/mod.rs, db.rs, ... [db internals]

This, however triggers the Clippy lint. Clippy Lints

I understand that what I am doing is sub-optimal, not only because I have to re-export a bunch of things in mod.rs to avoid the exact scenario the lint is about. But again, I really don't want to have things in mod.rs.

This page of the rust book Control Scope and Privacy with Modules - The Rust Programming Language, seems to suggest another style:

services/
services/auth/..[auth internals]...
services/log/..[log internals]...
services/db/..[db internals]..
services/auth.rs
services/log.rs
services/db.rs

I do not like that this one is breaking the encapsulation a little bit, ie, auth stuff is spread in two places, services/auth.rs (file) and services/auth/ (directory).

So do is this just a personal taste issue or am I missing something?

3 posts - 2 participants

Read full topic

🏷️ Rust_feed