How do you organize Rust modules? in directory, it's better


is there more than one way? (

10% in parent directory


I like turtles


10 votes · Closed

Rust now supports two ways to organize multi-file modules.

The traditional way, which is like Python's

One advantage is that the whole module is in one directory

The new alternative:

One advantage is that you don't have dozens of files with the same name (

Which way do you prefer?

(I'm having a hard time getting used to the new way and am thinking of reverting back, so I'm curious if I'm missing something...)

Start a personal dev blog on your domain for free and grow your readership.

3.4K+ developers have started their personal blogs on Hashnode in the last one month.

Write in Markdown · Publish articles on custom domain · Gain readership on day zero · Automatic GitHub backup and more

j's photo

I currently use the old structure for all my projects. personally the isolation that every module is one folder to me makes more sense. on the other hand having n mod files isn't that explicit either esp. if you have some shared logic for the specific module.

It's a tough one, I stick with the old one till I see a valid reason to switch besides eventual naming collisions. Which is weird since in other languages I always would try to avoid it ....

Not much help I guess :) Maybe I am missing something else Marco Alka what do you think?

Marco Alka's photo

It's so confusing to have multiple files open in the IDE, and I'd love to give them better names. However, it seems I somehow missed this new feature and I cannot find anything on the internet (though I also have to say that finding information on file hierarchy in Rust is a problem on its own...). Can you send me a link?

Even though I'd gladly use it, I think that the new alternative has a number of downsides:

  • When viewing the file and directory in a file explorer, they might be visually separated, which adds to confusion.
  • The module files might get mixed up with other regular files and it is difficult to tell them apart.

However, I think that a good IDE should somehow bring the files and folders back together. Maybe just display modules instead of actual files.

Mark's photo

Yeah I found it while searching searching some error messages I got while upgrading. Took a while to find back, but here it is: (along with the other changes)