Skip to content

Commit f27684e

Browse files
committed
modules: describe both module filename styles without giving a clear preference
1 parent 1dffb2b commit f27684e

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

src/items/modules.md

+7-12
Original file line numberDiff line numberDiff line change
@@ -65,27 +65,22 @@ not have a `path` attribute, the path to the file mirrors the logical [module
6565
path].
6666

6767
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.
68+
Ancestor module path components are directories, and the module's contents are in a file with the
69+
name of the module plus the `.rs` extension. Alternatively, the module's contents can also be in a
70+
file called `mod.rs` in a directory with the name of the module. It is not allowed to have both
71+
`$name.rs` and `$name/mod.rs`.
72+
7073
For example, the following module structure can have this corresponding
7174
filesystem structure:
7275

7376
Module Path | Filesystem Path | File Contents
7477
------------------------- | --------------- | -------------
7578
`crate` | `lib.rs` | `mod util;`
76-
`crate::util` | `util.rs` | `mod config;`
79+
`crate::util` | `util.rs` *or* `util/mod.rs` | `mod config;`
7780
`crate::util::config` | `util/config.rs` |
7881

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-
8582
> **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.
83+
> a module with nested children.
8984
9085
### The `path` attribute
9186

0 commit comments

Comments
 (0)