mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-01 16:29:18 +00:00
翻譯
This commit is contained in:
parent
5717f3ba32
commit
23ff14a68f
@ -1,22 +1,21 @@
|
|||||||
// strings3.rs
|
// strings3.rs
|
||||||
//
|
//
|
||||||
// Execute `rustlings hint strings3` or use the `hint` watch subcommand for a
|
// 執行 `rustlings hint strings3` 或使用 `hint` watch 子命令來獲取提示。
|
||||||
// hint.
|
|
||||||
|
|
||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
fn trim_me(input: &str) -> String {
|
fn trim_me(input: &str) -> String {
|
||||||
// TODO: Remove whitespace from both ends of a string!
|
// TODO: 去掉字串兩端的空白!
|
||||||
???
|
???
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compose_me(input: &str) -> String {
|
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 {
|
fn replace_me(input: &str) -> String {
|
||||||
// TODO: Replace "cars" in the string with "balloons"!
|
// TODO: 將字串中的 "cars" 替換為 "balloons"!
|
||||||
???
|
???
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
// strings4.rs
|
// strings4.rs
|
||||||
//
|
//
|
||||||
// Ok, here are a bunch of values-- some are `String`s, some are `&str`s. Your
|
// 好了,這裡有一堆值-- 有些是 `String`,有些是 `&str`。您的
|
||||||
// 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`
|
// 也就是說,在每行括號前添加 `string_slice` 或 `string`。
|
||||||
// before the parentheses on each line. If you're right, it will compile!
|
// 如果您正確的話,它將會編譯!
|
||||||
//
|
//
|
||||||
// No hints this time!
|
// 這次沒有提示!
|
||||||
|
|
||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
|
|||||||
@ -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)
|
||||||
|
|||||||
@ -1,12 +1,11 @@
|
|||||||
// modules1.rs
|
// modules1.rs
|
||||||
//
|
//
|
||||||
// Execute `rustlings hint modules1` or use the `hint` watch subcommand for a
|
// 執行 `rustlings hint modules1` 或使用 `hint` watch 子命令來獲取提示。
|
||||||
// hint.
|
|
||||||
|
|
||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
mod sausage_factory {
|
mod sausage_factory {
|
||||||
// Don't let anybody outside of this module see this!
|
// 不要讓這個模組外的任何人看到這個!
|
||||||
fn get_secret_recipe() -> String {
|
fn get_secret_recipe() -> String {
|
||||||
String::from("Ginger")
|
String::from("Ginger")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,25 +1,22 @@
|
|||||||
// modules2.rs
|
// modules2.rs
|
||||||
//
|
//
|
||||||
// You can bring module paths into scopes and provide new names for them with
|
// 您可以將模組路徑引入作用域並使用 'use' 和 'as' 關鍵字為它們提供新名稱。修復這些 'use' 語句以使代碼編譯。
|
||||||
// the 'use' and 'as' keywords. Fix these 'use' statements to make the code
|
|
||||||
// compile.
|
|
||||||
//
|
//
|
||||||
// Execute `rustlings hint modules2` or use the `hint` watch subcommand for a
|
// 執行 `rustlings hint modules2` 或使用 `hint` watch 子命令來獲取提示。
|
||||||
// hint.
|
|
||||||
|
|
||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
mod delicious_snacks {
|
mod delicious_snacks {
|
||||||
// TODO: Fix these use statements
|
// TODO: 修復這些 use 語句
|
||||||
use self::fruits::PEAR as ???
|
use self::fruits::PEAR as fruit;
|
||||||
use self::veggies::CUCUMBER as ???
|
use self::veggies::CUCUMBER as veggie;
|
||||||
|
|
||||||
mod fruits {
|
pub mod fruits {
|
||||||
pub const PEAR: &'static str = "Pear";
|
pub const PEAR: &'static str = "Pear";
|
||||||
pub const APPLE: &'static str = "Apple";
|
pub const APPLE: &'static str = "Apple";
|
||||||
}
|
}
|
||||||
|
|
||||||
mod veggies {
|
pub mod veggies {
|
||||||
pub const CUCUMBER: &'static str = "Cucumber";
|
pub const CUCUMBER: &'static str = "Cucumber";
|
||||||
pub const CARROT: &'static str = "Carrot";
|
pub const CARROT: &'static str = "Carrot";
|
||||||
}
|
}
|
||||||
@ -27,7 +24,7 @@ mod delicious_snacks {
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!(
|
println!(
|
||||||
"favorite snacks: {} and {}",
|
"最喜歡的蔬果: {} 和 {}",
|
||||||
delicious_snacks::fruit,
|
delicious_snacks::fruit,
|
||||||
delicious_snacks::veggie
|
delicious_snacks::veggie
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,21 +1,18 @@
|
|||||||
// modules3.rs
|
// modules3.rs
|
||||||
//
|
//
|
||||||
// You can use the 'use' keyword to bring module paths from modules from
|
// 您可以使用 'use' 關鍵字從任何地方,特別是從 Rust 標準庫中引入模組路徑到您的作用域中。從 std::time 模組引入 SystemTime 和 UNIX_EPOCH。
|
||||||
// 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!
|
|
||||||
//
|
//
|
||||||
// Execute `rustlings hint modules3` or use the `hint` watch subcommand for a
|
// 執行 `rustlings hint modules3` 或使用 `hint` watch 子命令來獲取提示。
|
||||||
// hint.
|
|
||||||
|
|
||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
// TODO: Complete this use statement
|
// TODO: 完成這個 use 語句
|
||||||
use ???
|
use ???
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
match SystemTime::now().duration_since(UNIX_EPOCH) {
|
match SystemTime::now().duration_since(UNIX_EPOCH) {
|
||||||
Ok(n) => println!("1970-01-01 00:00:00 UTC was {} seconds ago!", n.as_secs()),
|
Ok(n) => println!("1970-01-01 00:00:00 UTC 到現在已經過去 {} 秒了!", n.as_secs()),
|
||||||
Err(_) => panic!("SystemTime before UNIX EPOCH!"),
|
Err(_) => panic!("SystemTime 早於 UNIX EPOCH!"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user