File tree 1 file changed +35
-17
lines changed
src/rust-2018/module-system
1 file changed +35
-17
lines changed Original file line number Diff line number Diff line change @@ -169,34 +169,52 @@ mod submodule {
169
169
In Rust 2015, if you have a submodule:
170
170
171
171
``` rust,ignore
172
- /// foo.rs
173
- /// or
174
- /// foo/mod.rs
175
-
172
+ // This `mod` declaration looks for the `foo` module in
173
+ // `foo.rs` or `foo/mod.rs`.
176
174
mod foo;
177
175
```
178
176
179
177
It can live in ` foo.rs ` or ` foo/mod.rs ` . If it has submodules of its own, it
180
178
* must* be ` foo/mod.rs ` . So a ` bar ` submodule of ` foo ` would live at
181
179
` foo/bar.rs ` .
182
180
183
- In Rust 2018, ` mod.rs ` is no longer needed.
184
-
185
- ``` rust,ignore
186
- /// foo.rs
187
- /// foo/bar.rs
188
-
189
- mod foo;
190
-
191
- /// in foo.rs
192
- mod bar;
193
- ```
194
-
195
- ` foo.rs ` can just be ` foo.rs ` ,
181
+ In Rust 2018 the restriction that a module with submodules must be named
182
+ ` mod.rs ` is lifted. ` foo.rs ` can just be ` foo.rs ` ,
196
183
and the submodule is still ` foo/bar.rs ` . This eliminates the special
197
184
name, and if you have a bunch of files open in your editor, you can clearly
198
185
see their names, instead of having a bunch of tabs named ` mod.rs ` .
199
186
187
+ <table >
188
+ <thead >
189
+ <tr>
190
+ <th>Rust 2015</th>
191
+ <th>Rust 2018</th>
192
+ </tr>
193
+ </thead >
194
+ <tbody >
195
+ <tr>
196
+ <td>
197
+ <pre >
198
+ .
199
+ ├── lib.rs
200
+ └── foo/
201
+ ├── mod.rs
202
+ └── bar.rs
203
+ </pre >
204
+ </td>
205
+ <td>
206
+ <pre >
207
+ .
208
+ ├── lib.rs
209
+ ├── foo.rs
210
+ └── foo/
211
+ └── bar.rs
212
+ </pre >
213
+ </td>
214
+ </tr>
215
+ </tbody >
216
+ </table >
217
+
200
218
### ` use ` paths
201
219
202
220
![ Minimum Rust version: 1.32] ( https://img.shields.io/badge/Minimum%20Rust%20Version-1.32-brightgreen.svg )
You can’t perform that action at this time.
0 commit comments