|
|
|
@ -127,7 +127,7 @@ front_of_house::hosting::add_to_waitlist();
|
|
|
|
|
|
|
|
|
|
|
|
如果只是为了引用到指定模块中的对象,那么两种都可以,但是在实际使用时,需要遵循一个原则:**当代码被挪动位置时,尽量减少引用路径的修改**,相信大家都遇到过,修改了某处代码,导致所有路径都要挨个替换,这显然不是好的路径选择。
|
|
|
|
如果只是为了引用到指定模块中的对象,那么两种都可以,但是在实际使用时,需要遵循一个原则:**当代码被挪动位置时,尽量减少引用路径的修改**,相信大家都遇到过,修改了某处代码,导致所有路径都要挨个替换,这显然不是好的路径选择。
|
|
|
|
|
|
|
|
|
|
|
|
回到之前的例子,如果我们把 `front_of_house` 模块和 `eat_at_restaurant` 移动到一个模块中 `customer_experience`,那么绝对路径的引用方式就必须进行修改:`crate::customer_experience::front_of_house ...`,但是假设我们使用的相对路径,那么该路径就无需修改,因为它们两个的相对位置其实没有变:
|
|
|
|
回到之前的例子,如果我们把 `front_of_house` 模块和 `eat_at_restaurant` 移动到一个模块中 `customer_experience`,那么绝对路径的引用方式就必须进行修改:`crate::customer_experience::front_of_house ...`,但是假设我们使用的是相对路径,那么该路径就无需修改,因为它们两个的相对位置其实没有变:
|
|
|
|
|
|
|
|
|
|
|
|
```console
|
|
|
|
```console
|
|
|
|
crate
|
|
|
|
crate
|
|
|
|
@ -346,7 +346,7 @@ error[E0583]: file not found for module `front_of_house`
|
|
|
|
= help: to create the module `front_of_house`, create file "src/front_of_house.rs" or "src/front_of_house/mod.rs"
|
|
|
|
= help: to create the module `front_of_house`, create file "src/front_of_house.rs" or "src/front_of_house/mod.rs"
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
是的,如果需要将文件夹作为一个模块,我们需要进行显示指定暴露哪些子模块。按照上述的报错信息,我们有两种方法:
|
|
|
|
是的,如果需要将文件夹作为一个模块,我们需要进行显式指定暴露哪些子模块。按照上述的报错信息,我们有两种方法:
|
|
|
|
|
|
|
|
|
|
|
|
- 在 `front_of_house` 目录里创建一个 `mod.rs`,如果你使用的 `rustc` 版本 `1.30` 之前,这是唯一的方法。
|
|
|
|
- 在 `front_of_house` 目录里创建一个 `mod.rs`,如果你使用的 `rustc` 版本 `1.30` 之前,这是唯一的方法。
|
|
|
|
- 在 `front_of_house` **同级**目录里创建一个与模块(目录)**同名**的 rs 文件 `front_of_house.rs`,在新版本里,更建议使用这样的命名方式来避免项目中存在大量同名的 `mod.rs` 文件( Python 点了个 `踩`)。
|
|
|
|
- 在 `front_of_house` **同级**目录里创建一个与模块(目录)**同名**的 rs 文件 `front_of_house.rs`,在新版本里,更建议使用这样的命名方式来避免项目中存在大量同名的 `mod.rs` 文件( Python 点了个 `踩`)。
|
|
|
|
|