From 51bb48227cdba776b5d6b409ca65256438261b50 Mon Sep 17 00:00:00 2001 From: mg-chao Date: Mon, 10 Jan 2022 21:23:07 +0800 Subject: [PATCH] update: translate modules --- exercise/exercises/modules/README.md | 6 +++--- exercise/exercises/modules/modules1.rs | 4 ++-- exercise/exercises/modules/modules2.rs | 8 ++++---- exercise/exercises/modules/modules3.rs | 10 ++++------ exercise/info.toml | 19 +++++++++---------- 5 files changed, 22 insertions(+), 25 deletions(-) diff --git a/exercise/exercises/modules/README.md b/exercise/exercises/modules/README.md index 3dc8a482..9238f4db 100644 --- a/exercise/exercises/modules/README.md +++ b/exercise/exercises/modules/README.md @@ -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) diff --git a/exercise/exercises/modules/modules1.rs b/exercise/exercises/modules/modules1.rs index 1a2bd0dd..25d1079f 100644 --- a/exercise/exercises/modules/modules1.rs +++ b/exercise/exercises/modules/modules1.rs @@ -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") } diff --git a/exercise/exercises/modules/modules2.rs b/exercise/exercises/modules/modules2.rs index 87f0c458..ce9f2bd6 100644 --- a/exercise/exercises/modules/modules2.rs +++ b/exercise/exercises/modules/modules2.rs @@ -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 ??? diff --git a/exercise/exercises/modules/modules3.rs b/exercise/exercises/modules/modules3.rs index 8eed77df..495c9f34 100644 --- a/exercise/exercises/modules/modules3.rs +++ b/exercise/exercises/modules/modules3.rs @@ -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() { diff --git a/exercise/info.toml b/exercise/info.toml index 7b0c682a..41474569 100644 --- a/exercise/info.toml +++ b/exercise/info.toml @@ -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