Skip to content

modules: describe both module filename styles without giving a clear preference #1703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions src/items/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,22 @@ not have a `path` attribute, the path to the file mirrors the logical [module
path].

r[items.mod.outlined.search]
Ancestor module path components are directories, and the module's
contents are in a file with the name of the module plus the `.rs` extension.
Ancestor module path components are directories, and the module's contents are in a file with the
name of the module plus the `.rs` extension. Alternatively, the module's contents can also be in a
file called `mod.rs` in a directory with the name of the module. It is not allowed to have both
`$name.rs` and `$name/mod.rs`.

For example, the following module structure can have this corresponding
filesystem structure:

Module Path | Filesystem Path | File Contents
------------------------- | --------------- | -------------
`crate` | `lib.rs` | `mod util;`
`crate::util` | `util.rs` | `mod config;`
`crate::util::config` | `util/config.rs` |

r[items.mod.outlined.search-mod]
Module filenames may also be the name of the module as a directory with the
contents in a file named `mod.rs` within that directory. The above example can
alternately be expressed with `crate::util`'s contents in a file named
`util/mod.rs`. It is not allowed to have both `util.rs` and `util/mod.rs`.

> **Note**: Prior to `rustc` 1.30, using `mod.rs` files was the way to load
> a module with nested children. It is encouraged to use the new naming
> convention as it is more consistent, and avoids having many files named
> `mod.rs` within a project.
`crate::util` | `util.rs` *or* `util/mod.rs` | `mod config;`
`crate::util::config` | `util/config.rs` *or* `util/config/mod.rs` |

> **Note**: Prior to `rustc` 1.30, using `mod.rs` files was the only way to load
> a module with nested children. Rust 2018 added the new naming convention to be more consistent with modules that don't have submodules, and to avoid having many files named `mod.rs`.

### The `path` attribute

Expand Down