My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

How do you organize Rust modules?

Mark's photo
Mark
·Mar 23, 2019

mod.rs in directory, it's better

20%

is there more than one way? (mod.rs)

10%

my_module.rs in parent directory

10%

I like turtles

60%

10 votes · Closed

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

The traditional way, which is like Python's __init__.py:

lib.rs
my_module/
    mod.rs
    my_submodule.rs
    another_submodule.rs

One advantage is that the whole module is in one directory

The new alternative:

lib.rs
my_module.rs
my_module/
    my_submodule.rs
    another_submodule.rs

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

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...)