This commit is contained in:
TimLai666 2024-06-10 21:42:36 +08:00 committed by GitHub
parent 5717f3ba32
commit 23ff14a68f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 29 additions and 37 deletions

View File

@ -1,22 +1,21 @@
// strings3.rs
//
// Execute `rustlings hint strings3` or use the `hint` watch subcommand for a
// hint.
// 執行 `rustlings hint strings3` 或使用 `hint` watch 子命令來獲取提示。
// I AM NOT DONE
fn trim_me(input: &str) -> String {
// TODO: Remove whitespace from both ends of a string!
// TODO: 去掉字串兩端的空白!
???
}
fn compose_me(input: &str) -> String {
// TODO: Add " world!" to the string! There are multiple ways to do this!
// TODO: 添加 " world!" 到字串!有多種方法可以做到這一點!
???
}
fn replace_me(input: &str) -> String {
// TODO: Replace "cars" in the string with "balloons"!
// TODO: 將字串中的 "cars" 替換為 "balloons"
???
}

View File

@ -1,11 +1,11 @@
// strings4.rs
//
// Ok, here are a bunch of values-- some are `String`s, some are `&str`s. Your
// task is to call one of these two functions on each value depending on what
// you think each value is. That is, add either `string_slice` or `string`
// before the parentheses on each line. If you're right, it will compile!
// 好了,這裡有一堆值-- 有些是 `String`,有些是 `&str`。您的
// 任務是根據您認為每個值的類型來對每個值調用其中一個函數。
// 也就是說,在每行括號前添加 `string_slice` 或 `string`。
// 如果您正確的話,它將會編譯!
//
// No hints this time!
// 這次沒有提示!
// I AM NOT DONE

View File

@ -1,7 +1,7 @@
# 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)
- [模組系統](https://doc.rust-lang.org/book/ch07-00-managing-growing-projects-with-packages-crates-and-modules.html)

View File

@ -1,12 +1,11 @@
// modules1.rs
//
// Execute `rustlings hint modules1` or use the `hint` watch subcommand for a
// hint.
// 執行 `rustlings hint modules1` 或使用 `hint` watch 子命令來獲取提示。
// 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")
}

View File

@ -1,25 +1,22 @@
// 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.
// 您可以將模組路徑引入作用域並使用 'use' 和 'as' 關鍵字為它們提供新名稱。修復這些 'use' 語句以使代碼編譯。
//
// Execute `rustlings hint modules2` or use the `hint` watch subcommand for a
// hint.
// 執行 `rustlings hint modules2` 或使用 `hint` watch 子命令來獲取提示。
// I AM NOT DONE
mod delicious_snacks {
// TODO: Fix these use statements
use self::fruits::PEAR as ???
use self::veggies::CUCUMBER as ???
// TODO: 修復這些 use 語句
use self::fruits::PEAR as fruit;
use self::veggies::CUCUMBER as veggie;
mod fruits {
pub mod fruits {
pub const PEAR: &'static str = "Pear";
pub const APPLE: &'static str = "Apple";
}
mod veggies {
pub mod veggies {
pub const CUCUMBER: &'static str = "Cucumber";
pub const CARROT: &'static str = "Carrot";
}
@ -27,7 +24,7 @@ mod delicious_snacks {
fn main() {
println!(
"favorite snacks: {} and {}",
"最喜歡的蔬果: {} 和 {}",
delicious_snacks::fruit,
delicious_snacks::veggie
);

View File

@ -1,21 +1,18 @@
// 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!
// 您可以使用 'use' 關鍵字從任何地方,特別是從 Rust 標準庫中引入模組路徑到您的作用域中。從 std::time 模組引入 SystemTime 和 UNIX_EPOCH。
// 如果您能用一行完成它,會有額外的風格分!
//
// Execute `rustlings hint modules3` or use the `hint` watch subcommand for a
// hint.
// 執行 `rustlings hint modules3` 或使用 `hint` watch 子命令來獲取提示。
// I AM NOT DONE
// TODO: Complete this use statement
// TODO: 完成這個 use 語句
use ???
fn main() {
match SystemTime::now().duration_since(UNIX_EPOCH) {
Ok(n) => println!("1970-01-01 00:00:00 UTC was {} seconds ago!", n.as_secs()),
Err(_) => panic!("SystemTime before UNIX EPOCH!"),
Ok(n) => println!("1970-01-01 00:00:00 UTC 到現在已經過去 {} 秒了!", n.as_secs()),
Err(_) => panic!("SystemTime 早於 UNIX EPOCH"),
}
}