update: translate modules

pull/155/head
mg-chao 3 years ago
parent acfd8deed9
commit 51bb48227c

@ -1,7 +1,7 @@
# Modules
# 模块(Modules
In this section we'll give you an introduction to Rust's module system.
这部分我们将向你介绍 Rust 的模块系统。
## Further information
## 更多信息
- [The Module System](https://doc.rust-lang.org/book/ch07-00-managing-growing-projects-with-packages-crates-and-modules.html)

@ -1,10 +1,10 @@
// modules1.rs
// Make me compile! Execute `rustlings hint modules1` for hints :)
// 让我能够编译!执行 `rustex hint modules1` 获取提示 :)
// I AM NOT DONE
mod sausage_factory {
// Don't let anybody outside of this module see this!
// 确保它仅在当前模块可见。
fn get_secret_recipe() -> String {
String::from("Ginger")
}

@ -1,13 +1,13 @@
// modules2.rs
// You can bring module paths into scopes and provide new names for them with the
// 'use' and 'as' keywords. Fix these 'use' statements to make the code compile.
// Make me compile! Execute `rustlings hint modules2` for hints :)
// 你可以把模块引入作用域,并使用 'use' 和 'as' 关键字给它们取个别称.
// 修复 'use' 语句的相关代码以通过编译。
// 让我能够编译!执行 `rustex hint modules2` 获取提示 :)
// I AM NOT DONE
mod delicious_snacks {
// TODO: Fix these use statements
// TODO: 修复这些 'use' 语句
use self::fruits::PEAR as ???
use self::veggies::CUCUMBER as ???

@ -1,13 +1,11 @@
// modules3.rs
// You can use the 'use' keyword to bring module paths from modules from anywhere
// and especially from the Rust standard library into your scope.
// Bring SystemTime and UNIX_EPOCH
// from the std::time module. Bonus style points if you can do it with one line!
// Make me compile! Execute `rustlings hint modules3` for hints :)
// 你可以使用 'use' 关键字将任何位置的模块(特别是 Rust 标准库中的模块)引入作用域。
// 从 std::time 模块引入 SystemTime 和 UNIX_EPOCH。如果你能用一行代码解决就能获得额外得分。
// 让我能够编译!执行 `rustex hint modules3` 获取提示 :)
// I AM NOT DONE
// TODO: Complete this use statement
// TODO: 完成这个 `use` 语句
use ???
fn main() {

@ -333,28 +333,27 @@ name = "modules1"
path = "exercises/modules/modules1.rs"
mode = "compile"
hint = """
Everything is private in Rust by default-- but there's a keyword we can use
to make something public! The compiler error should point to the thing that
needs to be public."""
Rust 西private西public
西访"""
[[exercises]]
name = "modules2"
path = "exercises/modules/modules2.rs"
mode = "compile"
hint = """
The delicious_snacks module is trying to present an external interface that is
different than its internal structure (the `fruits` and `veggies` modules and
associated constants). Complete the `use` statements to fit the uses in main and
find the one keyword missing for both constants."""
delicious_snacks `fruits` `veggies`
main 使 `use` """
[[exercises]]
name = "modules3"
path = "exercises/modules/modules3.rs"
mode = "compile"
hint = """
UNIX_EPOCH and SystemTime are declared in the std::time module. Add a use statement
for these two to bring them into scope. You can use nested paths or the glob
operator to bring these two in using only one line."""
UNIX_EPOCH SystemTime std::time `use`
使nested paths
glob operator
{x,y,z} * """
# COLLECTIONS

Loading…
Cancel
Save