This commit is contained in:
TimLai666 2024-06-10 17:10:02 +08:00 committed by GitHub
parent ce247110f2
commit 2e8fc43a19
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 17 additions and 26 deletions

View File

@ -1,7 +1,6 @@
// move_semantics1.rs // move_semantics1.rs
// //
// Execute `rustlings hint move_semantics1` or use the `hint` watch subcommand // 執行 `rustlings hint move_semantics1` 或使用 `hint` watch 子命令來獲取提示。
// for a hint.
// I AM NOT DONE // I AM NOT DONE

View File

@ -1,9 +1,8 @@
// move_semantics2.rs // 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 // 執行 `rustlings hint move_semantics2` 或使用 `hint` watch 子命令來獲取提示。
// for a hint.
// I AM NOT DONE // I AM NOT DONE
@ -11,7 +10,7 @@
fn main() { fn main() {
let vec0 = vec![22, 44, 66]; 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!(vec0, vec![22, 44, 66]);
assert_eq!(vec1, vec![22, 44, 66, 88]); assert_eq!(vec1, vec![22, 44, 66, 88]);

View File

@ -1,10 +1,8 @@
// move_semantics3.rs // 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 // 執行 `rustlings hint move_semantics3` 或使用 `hint` watch 子命令來獲取提示。
// for a hint.
// I AM NOT DONE // I AM NOT DONE

View File

@ -1,11 +1,9 @@
// move_semantics4.rs // move_semantics4.rs
// //
// Refactor this code so that instead of passing `vec0` into the `fill_vec` // 重構這段代碼,使得 `vec0` 不再被傳遞給 `fill_vec` 函數,
// function, the Vector gets created in the function itself and passed back to // 而是在函數內部創建 Vector 並傳回給主函數。
// the main function.
// //
// Execute `rustlings hint move_semantics4` or use the `hint` watch subcommand // 執行 `rustlings hint move_semantics4` 或使用 `hint` watch 子命令來獲取提示。
// for a hint.
// I AM NOT DONE // I AM NOT DONE
@ -18,9 +16,9 @@ fn main() {
assert_eq!(vec1, vec![22, 44, 66, 88]); 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> { 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; let mut vec = vec;
vec.push(88); vec.push(88);

View File

@ -1,10 +1,8 @@
// move_semantics5.rs // move_semantics5.rs
// //
// Make me compile only by reordering the lines in `main()`, but without adding, // 使我編譯通過,只需重新排列 `main()` 中的行,但不添加、更改或刪除其中任何一行。
// changing or removing any of them.
// //
// Execute `rustlings hint move_semantics5` or use the `hint` watch subcommand // 執行 `rustlings hint move_semantics5` 或使用 `hint` watch 子命令來獲取提示。
// for a hint.
// I AM NOT DONE // I AM NOT DONE

View File

@ -1,9 +1,8 @@
// move_semantics6.rs // 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 // 執行 `rustlings hint move_semantics6` 或使用 `hint` watch 子命令來獲取提示。
// for a hint.
// I AM NOT DONE // I AM NOT DONE
@ -15,12 +14,12 @@ fn main() {
string_uppercase(&data); string_uppercase(&data);
} }
// Should not take ownership // 不應該取得所有權
fn get_char(data: String) -> char { fn get_char(data: String) -> char {
data.chars().last().unwrap() data.chars().last().unwrap()
} }
// Should take ownership // 應該取得所有權
fn string_uppercase(mut data: &String) { fn string_uppercase(mut data: &String) {
data = &data.to_uppercase(); data = &data.to_uppercase();