From 7dc4e78ba7aa0438442bd7de77dca0bf8b17950b Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Mon, 22 Aug 2016 16:44:19 -0400 Subject: [PATCH] Clear up the module rules --- src/ch07-02-mod-and-the-filesystem.md | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/ch07-02-mod-and-the-filesystem.md b/src/ch07-02-mod-and-the-filesystem.md index 246bf6587..dbbf6e35f 100644 --- a/src/ch07-02-mod-and-the-filesystem.md +++ b/src/ch07-02-mod-and-the-filesystem.md @@ -269,9 +269,23 @@ $ cargo build $ ``` -It works! In summary, these are the two rules of modules with regards to files: +It works! In summary, these are the rules of modules with regards to files: -* If a module named `foo` has no submodules, it will be named `foo.rs`. -* If a module named `foo` does have submodules, it will be named `foo/mod.rs`. +* If a module named `foo` has no submodules, you should put the declarations in + the `foo` module in a file named `foo.rs`. +* If a module named `foo` does have submodules, you should put the declarations + for `foo` in a file named `foo/mod.rs`. +* The first two rules apply recursively, so that if a module named `foo` has a + submodule named `bar` and `bar` does not have submodules, you should have the + following files in your `src` directory: + + ``` + ├── foo + │   ├── bar.rs (contains the declarations in `foo::bar`) + │   └── mod.rs (contains the declarations in `foo`, including `mod bar`) + ``` + +* The modules themselves should be declared in their parent module's file using + the `mod` keyword. Next, we'll talk about the `pub` keyword, and get rid of those warnings!