Skip to content

Commit 19e847e

Browse files
committedDec 21, 2024
modules: describe both module filename styles without giving a clear preference
1 parent 1dffb2b commit 19e847e

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed
 

‎src/items/modules.md

+7-13
Original file line numberDiff line numberDiff line change
@@ -64,28 +64,22 @@ A module without a body is loaded from an external file. When the module does
6464
not have a `path` attribute, the path to the file mirrors the logical [module
6565
path].
6666

67-
r[items.mod.outlined.search]
68-
Ancestor module path components are directories, and the module's
69-
contents are in a file with the name of the module plus the `.rs` extension.
67+
r[items.mod.outlined.search] Ancestor module path components are directories, and the module's
68+
contents are in a file with the name of the module plus the `.rs` extension. Alternatively, the
69+
module's contents can also be in a file called `mod.rs` in a directory with the name of the module.
70+
It is not allowed to have both `$name.rs` and `$name/mod.rs`.
71+
7072
For example, the following module structure can have this corresponding
7173
filesystem structure:
7274

7375
Module Path | Filesystem Path | File Contents
7476
------------------------- | --------------- | -------------
7577
`crate` | `lib.rs` | `mod util;`
76-
`crate::util` | `util.rs` | `mod config;`
78+
`crate::util` | `util.rs` *or* `util/mod.rs` | `mod config;`
7779
`crate::util::config` | `util/config.rs` |
7880

79-
r[items.mod.outlined.search-mod]
80-
Module filenames may also be the name of the module as a directory with the
81-
contents in a file named `mod.rs` within that directory. The above example can
82-
alternately be expressed with `crate::util`'s contents in a file named
83-
`util/mod.rs`. It is not allowed to have both `util.rs` and `util/mod.rs`.
84-
8581
> **Note**: Prior to `rustc` 1.30, using `mod.rs` files was the way to load
86-
> a module with nested children. It is encouraged to use the new naming
87-
> convention as it is more consistent, and avoids having many files named
88-
> `mod.rs` within a project.
82+
> a module with nested children.
8983
9084
### The `path` attribute
9185

0 commit comments

Comments
 (0)