From fab3e27cfbbed8873146ae7ae00181be7dcf2d25 Mon Sep 17 00:00:00 2001 From: jwcesign Date: Tue, 19 Mar 2024 11:41:04 +0800 Subject: [PATCH] =?UTF-8?q?doc:=20=E8=AE=A9=E6=96=87=E4=BB=B6=E5=92=8Cmod?= =?UTF-8?q?=E7=9A=84=E5=AF=B9=E5=BA=94=E6=9B=B4=E6=B8=85=E6=99=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit doc: 让文件和mod的对应更清晰 --- src/basic/crate-module/module.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/basic/crate-module/module.md b/src/basic/crate-module/module.md index c9785104..b0b31af8 100644 --- a/src/basic/crate-module/module.md +++ b/src/basic/crate-module/module.md @@ -351,13 +351,23 @@ error[E0583]: file not found for module `front_of_house` - 在 `front_of_house` 目录里创建一个 `mod.rs`,如果你使用的 `rustc` 版本 `1.30` 之前,这是唯一的方法。 - 在 `front_of_house` **同级**目录里创建一个与模块(目录)**同名**的 rs 文件 `front_of_house.rs`,在新版本里,更建议使用这样的命名方式来避免项目中存在大量同名的 `mod.rs` 文件( Python 点了个 `踩`)。 -而无论是上述哪个方式创建的文件,其内容都是一样的,你需要定义你的子模块(子模块名与文件名相同): +如果使用第二种方式,文件结构将如下所示: +```shell +src +├── front_of_house +│ └── hosting.rs +├── front_of_house.rs +└── lib.rs +``` + +而无论是上述哪个方式创建的文件,其内容都是一样的,你需要在定义你(`mod.rs` 或 `front_of_house.rs`)的子模块(子模块名与文件名相同): ```rust pub mod hosting; // pub mod serving; ``` + ## 课后练习 > [Rust By Practice](https://practice-zh.course.rs/crate-module/module.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/crate-module/module.md)。