mirror of
https://github.com/rust-lang/rustlings.git
synced 2025-12-28 23:09:18 +00:00
翻譯
This commit is contained in:
parent
ce247110f2
commit
2e8fc43a19
@ -1,7 +1,6 @@
|
||||
// move_semantics1.rs
|
||||
//
|
||||
// Execute `rustlings hint move_semantics1` or use the `hint` watch subcommand
|
||||
// for a hint.
|
||||
// 執行 `rustlings hint move_semantics1` 或使用 `hint` watch 子命令來獲取提示。
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
// move_semantics2.rs
|
||||
//
|
||||
// Make the test pass by finding a way to keep both Vecs separate!
|
||||
// 使測試通過,找到一種方法讓兩個 Vec 保持分離!
|
||||
//
|
||||
// Execute `rustlings hint move_semantics2` or use the `hint` watch subcommand
|
||||
// for a hint.
|
||||
// 執行 `rustlings hint move_semantics2` 或使用 `hint` watch 子命令來獲取提示。
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
@ -11,7 +10,7 @@
|
||||
fn main() {
|
||||
let vec0 = vec![22, 44, 66];
|
||||
|
||||
let vec1 = fill_vec(vec0);
|
||||
let vec1 = fill_vec(vec0.clone());
|
||||
|
||||
assert_eq!(vec0, vec![22, 44, 66]);
|
||||
assert_eq!(vec1, vec![22, 44, 66, 88]);
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
// move_semantics3.rs
|
||||
//
|
||||
// Make me compile without adding new lines -- just changing existing lines! (no
|
||||
// lines with multiple semicolons necessary!)
|
||||
// 使我編譯通過且不新增新行 -- 只更改現有行!(不需要多個分號的行!)
|
||||
//
|
||||
// Execute `rustlings hint move_semantics3` or use the `hint` watch subcommand
|
||||
// for a hint.
|
||||
// 執行 `rustlings hint move_semantics3` 或使用 `hint` watch 子命令來獲取提示。
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
// move_semantics4.rs
|
||||
//
|
||||
// Refactor this code so that instead of passing `vec0` into the `fill_vec`
|
||||
// function, the Vector gets created in the function itself and passed back to
|
||||
// the main function.
|
||||
// 重構這段代碼,使得 `vec0` 不再被傳遞給 `fill_vec` 函數,
|
||||
// 而是在函數內部創建 Vector 並傳回給主函數。
|
||||
//
|
||||
// Execute `rustlings hint move_semantics4` or use the `hint` watch subcommand
|
||||
// for a hint.
|
||||
// 執行 `rustlings hint move_semantics4` 或使用 `hint` watch 子命令來獲取提示。
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
@ -18,9 +16,9 @@ fn main() {
|
||||
assert_eq!(vec1, vec![22, 44, 66, 88]);
|
||||
}
|
||||
|
||||
// `fill_vec()` no longer takes `vec: Vec<i32>` as argument - don't change this!
|
||||
// `fill_vec()` 不再接受 `vec: Vec<i32>` 作為參數 - 不要更改這點!
|
||||
fn fill_vec() -> Vec<i32> {
|
||||
// Instead, let's create and fill the Vec in here - how do you do that?
|
||||
// 相反,讓我們在這裡創建並填充 Vec - 您該怎麼做呢?
|
||||
let mut vec = vec;
|
||||
|
||||
vec.push(88);
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
// move_semantics5.rs
|
||||
//
|
||||
// Make me compile only by reordering the lines in `main()`, but without adding,
|
||||
// changing or removing any of them.
|
||||
// 使我編譯通過,只需重新排列 `main()` 中的行,但不添加、更改或刪除其中任何一行。
|
||||
//
|
||||
// Execute `rustlings hint move_semantics5` or use the `hint` watch subcommand
|
||||
// for a hint.
|
||||
// 執行 `rustlings hint move_semantics5` 或使用 `hint` watch 子命令來獲取提示。
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
// move_semantics6.rs
|
||||
//
|
||||
// You can't change anything except adding or removing references.
|
||||
// 您只能添加或刪除引用(reference),不能更改其他任何內容。
|
||||
//
|
||||
// Execute `rustlings hint move_semantics6` or use the `hint` watch subcommand
|
||||
// for a hint.
|
||||
// 執行 `rustlings hint move_semantics6` 或使用 `hint` watch 子命令來獲取提示。
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
@ -15,12 +14,12 @@ fn main() {
|
||||
string_uppercase(&data);
|
||||
}
|
||||
|
||||
// Should not take ownership
|
||||
// 不應該取得所有權
|
||||
fn get_char(data: String) -> char {
|
||||
data.chars().last().unwrap()
|
||||
}
|
||||
|
||||
// Should take ownership
|
||||
// 應該取得所有權
|
||||
fn string_uppercase(mut data: &String) {
|
||||
data = &data.to_uppercase();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user