mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-04-16 13:48:52 +02:00
Filesystem slide rework (#1002)
* Filesystem slide rework (2015 is over) * cleanup * Cleanup text * Specify "current versions" Co-authored-by: Martin Geisler <martin@geisler.net> --------- Co-authored-by: Martin Geisler <martin@geisler.net>
This commit is contained in:
parent
94e5db7ddb
commit
2c3aa82af5
@ -1,20 +1,13 @@
|
||||
# Filesystem Hierarchy
|
||||
|
||||
The module content can be omitted:
|
||||
Omitting the module content will tell Rust to look for it in another file:
|
||||
|
||||
```rust,editable,compile_fail
|
||||
mod garden;
|
||||
```
|
||||
|
||||
The `garden` module content is found at:
|
||||
|
||||
* `src/garden.rs` (modern Rust 2018 style)
|
||||
* `src/garden/mod.rs` (older Rust 2015 style)
|
||||
|
||||
Similarly, a `garden::vegetables` module can be found at:
|
||||
|
||||
* `src/garden/vegetables.rs` (modern Rust 2018 style)
|
||||
* `src/garden/vegetables/mod.rs` (older Rust 2015 style)
|
||||
This tells rust that the `garden` module content is found at `src/garden.rs`.
|
||||
Similarly, a `garden::vegetables` module can be found at `src/garden/vegetables.rs`.
|
||||
|
||||
The `crate` root is in:
|
||||
|
||||
@ -41,10 +34,12 @@ pub fn harvest(garden: &mut Garden) { todo!() }
|
||||
|
||||
<details>
|
||||
|
||||
* The change from `module/mod.rs` to `module.rs` doesn't preclude the use of submodules in Rust 2018.
|
||||
(It was mandatory in Rust 2015.)
|
||||
* Before Rust 2018, modules needed to be located at `module/mod.rs` instead of `module.rs`, and this is still a working alternative for editions after 2018.
|
||||
|
||||
The following is valid:
|
||||
* The main reason to introduce `filename.rs` as alternative to `filename/mod.rs`
|
||||
was because many files named `mod.rs` can be hard to distinguish in IDEs.
|
||||
|
||||
* Deeper nesting can use folders, even if the main module is a file:
|
||||
|
||||
```ignore
|
||||
src/
|
||||
@ -54,11 +49,7 @@ pub fn harvest(garden: &mut Garden) { todo!() }
|
||||
└── sub_module.rs
|
||||
```
|
||||
|
||||
* The main reason for the change is to prevent many files named `mod.rs`, which can be hard
|
||||
to distinguish in IDEs.
|
||||
|
||||
* Rust will look for modules in `modulename/mod.rs` and `modulename.rs`, but this can be changed
|
||||
with a compiler directive:
|
||||
* The place rust will look for modules can be changed with a compiler directive:
|
||||
|
||||
```rust,ignore
|
||||
#[path = "some/path.rs"]
|
||||
|
Loading…
x
Reference in New Issue
Block a user