mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-04-26 17:23:01 +02:00
parent
e199aee30d
commit
b573caad05
216
po/zh-TW.po
216
po/zh-TW.po
@ -5232,7 +5232,7 @@ msgstr ""
|
||||
#: src/methods/example.md:46 src/pattern-matching.md:25
|
||||
#: src/pattern-matching/match-guards.md:22 src/control-flow/blocks.md:42
|
||||
msgid "Key Points:"
|
||||
msgstr ""
|
||||
msgstr "重點:"
|
||||
|
||||
#: src/structs.md:33
|
||||
msgid ""
|
||||
@ -6406,6 +6406,24 @@ msgid ""
|
||||
"}\n"
|
||||
"```"
|
||||
msgstr ""
|
||||
"```rust,editable\n"
|
||||
"fn main() {\n"
|
||||
" let x = {\n"
|
||||
" let y = 10;\n"
|
||||
" println!(\"y: {y}\");\n"
|
||||
" let z = {\n"
|
||||
" let w = {\n"
|
||||
" 3 + 4\n"
|
||||
" };\n"
|
||||
" println!(\"w: {w}\");\n"
|
||||
" y * w\n"
|
||||
" };\n"
|
||||
" println!(\"z: {z}\");\n"
|
||||
" z - y\n"
|
||||
" };\n"
|
||||
" println!(\"x: {x}\");\n"
|
||||
"}\n"
|
||||
"```"
|
||||
|
||||
#: src/control-flow/blocks.md:25
|
||||
msgid ""
|
||||
@ -6425,6 +6443,15 @@ msgid ""
|
||||
"}\n"
|
||||
"```"
|
||||
msgstr ""
|
||||
"```rust,editable\n"
|
||||
"fn double(x: i32) -> i32 {\n"
|
||||
" x + x\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"fn main() {\n"
|
||||
" println!(\"doubled: {}\", double(7));\n"
|
||||
"}\n"
|
||||
"```"
|
||||
|
||||
#: src/control-flow/blocks.md:38
|
||||
msgid ""
|
||||
@ -6473,6 +6500,16 @@ msgid ""
|
||||
"}\n"
|
||||
"```"
|
||||
msgstr ""
|
||||
"```rust,editable\n"
|
||||
"fn main() {\n"
|
||||
" let mut x = 10;\n"
|
||||
" if x % 2 == 0 {\n"
|
||||
" x = x / 2;\n"
|
||||
" } else {\n"
|
||||
" x = 3 * x + 1;\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"```"
|
||||
|
||||
#: src/control-flow/if-expressions.md:18
|
||||
msgid ""
|
||||
@ -6495,6 +6532,16 @@ msgid ""
|
||||
"}\n"
|
||||
"```"
|
||||
msgstr ""
|
||||
"```rust,editable\n"
|
||||
"fn main() {\n"
|
||||
" let mut x = 10;\n"
|
||||
" x = if x % 2 == 0 {\n"
|
||||
" x / 2\n"
|
||||
" } else {\n"
|
||||
" 3 * x + 1\n"
|
||||
" };\n"
|
||||
"}\n"
|
||||
"```"
|
||||
|
||||
#: src/control-flow/if-expressions.md:35
|
||||
msgid ""
|
||||
@ -6507,7 +6554,7 @@ msgstr ""
|
||||
|
||||
#: src/control-flow/if-let-expressions.md:1
|
||||
msgid "# `if let` expressions"
|
||||
msgstr ""
|
||||
msgstr "# `if let` 運算式"
|
||||
|
||||
#: src/control-flow/if-let-expressions.md:3
|
||||
msgid ""
|
||||
@ -6517,6 +6564,8 @@ msgid ""
|
||||
"lets you execute different code depending on whether a value matches a "
|
||||
"pattern:"
|
||||
msgstr ""
|
||||
"[`if let` 運算式](https://doc.rust-lang.org/reference/expressions/if-expr."
|
||||
"html#if-let-expressions)可讓您根據值是否符合模式,執行不同的程式碼:"
|
||||
|
||||
#: src/control-flow/if-let-expressions.md:7
|
||||
msgid ""
|
||||
@ -6531,6 +6580,16 @@ msgid ""
|
||||
"}\n"
|
||||
"```"
|
||||
msgstr ""
|
||||
"```rust,editable\n"
|
||||
"fn main() {\n"
|
||||
" let arg = std::env::args().next();\n"
|
||||
" if let Some(value) = arg {\n"
|
||||
" println!(\"Program name: {value}\");\n"
|
||||
" } else {\n"
|
||||
" println!(\"Missing name?\");\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"```"
|
||||
|
||||
#: src/control-flow/if-let-expressions.md:18
|
||||
#: src/control-flow/while-let-expressions.md:21
|
||||
@ -6540,6 +6599,7 @@ msgid ""
|
||||
"in\n"
|
||||
"Rust."
|
||||
msgstr ""
|
||||
"如要進一步瞭解 Rust 中的模式,請參閱「[模式比對](../pattern-matching.md)」。"
|
||||
|
||||
#: src/control-flow/if-let-expressions.md:23
|
||||
msgid ""
|
||||
@ -6566,10 +6626,30 @@ msgid ""
|
||||
" Some(item.to_uppercase())\n"
|
||||
" }"
|
||||
msgstr ""
|
||||
"* `if let` 可以比 `match` 更為精簡,例如只有一個有趣案例時。相對地,`match` "
|
||||
"必須涵蓋所有分支。\n"
|
||||
"* 常見用途是在使用 `Option` 時處理 `Some` 值。\n"
|
||||
"* 與 `match` 不同,`if let` 不會為模式比對支援成立條件子句。\n"
|
||||
"* 自 1.65 版起,類似的 [let-else](https://doc.rust-lang.org/rust-by-example/"
|
||||
"flow_control/let_else.html) 結構可以解構指派項目,或在失敗時具有不會傳回的區"
|
||||
"塊分支 (panic/return/break/continue):\n"
|
||||
"\n"
|
||||
" ```rust,editable\n"
|
||||
" fn main() {\n"
|
||||
" println!(\"{:?}\", second_word_to_upper(\"foo bar\"));\n"
|
||||
" }\n"
|
||||
" \n"
|
||||
" fn second_word_to_upper(s: &str) -> Option<String> {\n"
|
||||
" let mut it = s.split(' ');\n"
|
||||
" let (Some(_), Some(item)) = (it.next(), it.next()) else {\n"
|
||||
" return None;\n"
|
||||
" };\n"
|
||||
" Some(item.to_uppercase())\n"
|
||||
" }"
|
||||
|
||||
#: src/control-flow/while-expressions.md:1
|
||||
msgid "# `while` loops"
|
||||
msgstr ""
|
||||
msgstr "# `while` 迴圈"
|
||||
|
||||
#: src/control-flow/while-expressions.md:3
|
||||
msgid ""
|
||||
@ -6577,6 +6657,8 @@ msgid ""
|
||||
"expr.html#predicate-loops)\n"
|
||||
"works very similar to other languages:"
|
||||
msgstr ""
|
||||
"[`while` 關鍵字](https://doc.rust-lang.org/reference/expressions/loop-expr."
|
||||
"html#predicate-loops)的運作方式與其他語言非常相似:"
|
||||
|
||||
#: src/control-flow/while-expressions.md:6
|
||||
msgid ""
|
||||
@ -6594,10 +6676,23 @@ msgid ""
|
||||
"}\n"
|
||||
"```"
|
||||
msgstr ""
|
||||
"```rust,editable\n"
|
||||
"fn main() {\n"
|
||||
" let mut x = 10;\n"
|
||||
" while x != 1 {\n"
|
||||
" x = if x % 2 == 0 {\n"
|
||||
" x / 2\n"
|
||||
" } else {\n"
|
||||
" 3 * x + 1\n"
|
||||
" };\n"
|
||||
" }\n"
|
||||
" println!(\"Final x: {x}\");\n"
|
||||
"}\n"
|
||||
"```"
|
||||
|
||||
#: src/control-flow/while-let-expressions.md:1
|
||||
msgid "# `while let` loops"
|
||||
msgstr ""
|
||||
msgstr "# `while let` 迴圈"
|
||||
|
||||
#: src/control-flow/while-let-expressions.md:3
|
||||
msgid ""
|
||||
@ -6605,6 +6700,9 @@ msgid ""
|
||||
"reference/expressions/loop-expr.html#predicate-pattern-loops)\n"
|
||||
"variant which repeatedly tests a value against a pattern:"
|
||||
msgstr ""
|
||||
"和 `if let` 的情況一樣,有一個 [`while let`](https://doc.rust-lang.org/"
|
||||
"reference/expressions/loop-expr.html#predicate-pattern-loops) 變數可針對模式"
|
||||
"重複測試值:"
|
||||
|
||||
#: src/control-flow/while-let-expressions.md:6
|
||||
msgid ""
|
||||
@ -6619,6 +6717,16 @@ msgid ""
|
||||
"}\n"
|
||||
"```"
|
||||
msgstr ""
|
||||
"```rust,editable\n"
|
||||
"fn main() {\n"
|
||||
" let v = vec![10, 20, 30];\n"
|
||||
" let mut iter = v.into_iter();\n"
|
||||
"\n"
|
||||
" while let Some(x) = iter.next() {\n"
|
||||
" println!(\"x: {x}\");\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"```"
|
||||
|
||||
#: src/control-flow/while-let-expressions.md:17
|
||||
msgid ""
|
||||
@ -6628,6 +6736,9 @@ msgid ""
|
||||
"will\n"
|
||||
"return `None`. The `while let` lets us keep iterating through all items."
|
||||
msgstr ""
|
||||
"`v.iter()` 傳回的疊代器會在每次呼叫 `next()` 時傳回 `Option<i32>`。疊代器會在"
|
||||
"完成後才傳回 `Some(x)`,之後則會傳回 `None`。`while let` 可讓我們持續疊代所有"
|
||||
"項目。"
|
||||
|
||||
#: src/control-flow/while-let-expressions.md:26
|
||||
msgid ""
|
||||
@ -6638,10 +6749,14 @@ msgid ""
|
||||
"The `while let` provides syntactic sugar for the above scenario.\n"
|
||||
" "
|
||||
msgstr ""
|
||||
"* 請指出只要值符合模式,`while let` 迴圈就會持續運作。\n"
|
||||
"* 您可以將 `while let` 迴圈重寫為無限迴圈,並加上會在無法為 `iter.next()` 取"
|
||||
"消包裝值的情況下結束的 if 陳述式。`while let` 可為上述情況提供語法糖。\n"
|
||||
" "
|
||||
|
||||
#: src/control-flow/for-expressions.md:1
|
||||
msgid "# `for` loops"
|
||||
msgstr ""
|
||||
msgstr "# `for` 迴圈"
|
||||
|
||||
#: src/control-flow/for-expressions.md:3
|
||||
msgid ""
|
||||
@ -6649,6 +6764,9 @@ msgid ""
|
||||
"related to the [`while let` loop](while-let-expression.md). It will\n"
|
||||
"automatically call `into_iter()` on the expression and then iterate over it:"
|
||||
msgstr ""
|
||||
"[`for` 迴圈](https://doc.rust-lang.org/std/keyword.for.html)與 [`while let` "
|
||||
"迴圈](while-let-expression.md)密切相關,會自動在運算式上呼叫 `into_iter()`,"
|
||||
"然後對其進行疊代:"
|
||||
|
||||
#: src/control-flow/for-expressions.md:7
|
||||
msgid ""
|
||||
@ -6666,10 +6784,23 @@ msgid ""
|
||||
"}\n"
|
||||
"```"
|
||||
msgstr ""
|
||||
"```rust,editable\n"
|
||||
"fn main() {\n"
|
||||
" let v = vec![10, 20, 30];\n"
|
||||
"\n"
|
||||
" for x in v {\n"
|
||||
" println!(\"x: {x}\");\n"
|
||||
" }\n"
|
||||
" \n"
|
||||
" for i in (0..10).step_by(2) {\n"
|
||||
" println!(\"i: {i}\");\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"```"
|
||||
|
||||
#: src/control-flow/for-expressions.md:21
|
||||
msgid "You can use `break` and `continue` here as usual."
|
||||
msgstr ""
|
||||
msgstr "您可以照常使用 `break` 和 `continue`。"
|
||||
|
||||
#: src/control-flow/for-expressions.md:25
|
||||
msgid ""
|
||||
@ -6680,10 +6811,15 @@ msgid ""
|
||||
"* Modify the elements in the vector and explain the compiler errors. Change "
|
||||
"vector `v` to be mutable and the for loop to `for x in v.iter_mut()`."
|
||||
msgstr ""
|
||||
"* 在 Rust 中,索引疊代不是只適用於該情況的特殊語法。\n"
|
||||
"* `(0..10)` 是實作 `Iterator` 特徵的範圍。\n"
|
||||
"* `step_by` 這個方法會傳回另一個略過其他所有元素的 `Iterator`。\n"
|
||||
"* 請修改向量中的元素,並說明編譯器錯誤。將向量 `v` 變更為可變動項,並將 for "
|
||||
"迴圈變更為 `for x in v.iter_mut()`。"
|
||||
|
||||
#: src/control-flow/loop-expressions.md:1
|
||||
msgid "# `loop` expressions"
|
||||
msgstr ""
|
||||
msgstr "# `loop` 運算式"
|
||||
|
||||
#: src/control-flow/loop-expressions.md:3
|
||||
msgid ""
|
||||
@ -6691,10 +6827,12 @@ msgid ""
|
||||
"expressions/loop-expr.html#infinite-loops)\n"
|
||||
"which creates an endless loop."
|
||||
msgstr ""
|
||||
"最後,有一個 [`loop` 關鍵字](https://doc.rust-lang.org/reference/expressions/"
|
||||
"loop-expr.html#infinite-loops)會建立無限迴圈。"
|
||||
|
||||
#: src/control-flow/loop-expressions.md:6
|
||||
msgid "Here you must either `break` or `return` to stop the loop:"
|
||||
msgstr ""
|
||||
msgstr "這時您必須執行 `break` 或 `return` 來停止迴圈:"
|
||||
|
||||
#: src/control-flow/loop-expressions.md:8
|
||||
msgid ""
|
||||
@ -6715,6 +6853,22 @@ msgid ""
|
||||
"}\n"
|
||||
"```"
|
||||
msgstr ""
|
||||
"```rust,editable\n"
|
||||
"fn main() {\n"
|
||||
" let mut x = 10;\n"
|
||||
" loop {\n"
|
||||
" x = if x % 2 == 0 {\n"
|
||||
" x / 2\n"
|
||||
" } else {\n"
|
||||
" 3 * x + 1\n"
|
||||
" };\n"
|
||||
" if x == 1 {\n"
|
||||
" break;\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" println!(\"Final x: {x}\");\n"
|
||||
"}\n"
|
||||
"```"
|
||||
|
||||
#: src/control-flow/loop-expressions.md:27
|
||||
msgid ""
|
||||
@ -6725,10 +6879,13 @@ msgid ""
|
||||
"(unlike\n"
|
||||
" `while` and `for` loops)."
|
||||
msgstr ""
|
||||
"* 請使用 `break 8` 等值中斷 `loop`,然後顯示出來。\n"
|
||||
"* 請注意,`loop` 是唯一會傳回重要值的迴圈結構。這是因為系統保證至少會輸入一次"
|
||||
"此迴圈結構,這一點不同於 `while` 和 `for` 迴圈。"
|
||||
|
||||
#: src/control-flow/match-expressions.md:1
|
||||
msgid "# `match` expressions"
|
||||
msgstr ""
|
||||
msgstr "# `match` 運算式"
|
||||
|
||||
#: src/control-flow/match-expressions.md:3
|
||||
msgid ""
|
||||
@ -6738,6 +6895,9 @@ msgid ""
|
||||
"works\n"
|
||||
"like a series of `if let` expressions:"
|
||||
msgstr ""
|
||||
"[`match` 關鍵字](https://doc.rust-lang.org/reference/expressions/match-expr."
|
||||
"html)是用來將值與一或多個模式進行比對。因此,這個關鍵字的運作方式類似於一系列"
|
||||
"的 `if let` 運算式:"
|
||||
|
||||
#: src/control-flow/match-expressions.md:7
|
||||
msgid ""
|
||||
@ -6754,12 +6914,26 @@ msgid ""
|
||||
"}\n"
|
||||
"```"
|
||||
msgstr ""
|
||||
"```rust,editable\n"
|
||||
"fn main() {\n"
|
||||
" match std::env::args().next().as_deref() {\n"
|
||||
" Some(\"cat\") => println!(\"Will do cat things\"),\n"
|
||||
" Some(\"ls\") => println!(\"Will ls some files\"),\n"
|
||||
" Some(\"mv\") => println!(\"Let's move some files\"),\n"
|
||||
" Some(\"rm\") => println!(\"Uh, dangerous!\"),\n"
|
||||
" None => println!(\"Hmm, no program name?\"),\n"
|
||||
" _ => println!(\"Unknown program name!\"),\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"```"
|
||||
|
||||
#: src/control-flow/match-expressions.md:20
|
||||
msgid ""
|
||||
"Like `if let`, each match arm must have the same type. The type is the last\n"
|
||||
"expression of the block, if any. In the example above, the type is `()`."
|
||||
msgstr ""
|
||||
"和 `if let` 一樣,每個比對臂都必須具有相同類型。類型是區塊的最後一個運算式 "
|
||||
"(如有)。在上述範例中,類型為 `()`。"
|
||||
|
||||
#: src/control-flow/match-expressions.md:28
|
||||
msgid ""
|
||||
@ -6772,6 +6946,13 @@ msgid ""
|
||||
" * We can now use pattern matching to match against the `&str` inside "
|
||||
"`Option`."
|
||||
msgstr ""
|
||||
"* 請將比對運算式儲存為變數,然後顯示出來。\n"
|
||||
"* 請移除 `.as_deref()` 並說明錯誤。\n"
|
||||
" * `std::env::args().next()` 會傳回 `Option<String>`,但我們無法與"
|
||||
"`String` 進行比對。\n"
|
||||
" * `as_deref()` 會將 `Option<T>` 轉換成 `Option<&T::Target>`。在我們的案例"
|
||||
"中,這會將 `Option<String>` 轉換成`Option<&str>`。\n"
|
||||
" * 我們現在可以使用模式比對,與 `Option` 內的 `&str` 進行比對。"
|
||||
|
||||
#: src/control-flow/break-continue.md:1
|
||||
msgid "# `break` and `continue`"
|
||||
@ -6819,6 +7000,23 @@ msgid ""
|
||||
"}\n"
|
||||
"```"
|
||||
msgstr ""
|
||||
"```rust,editable\n"
|
||||
"fn main() {\n"
|
||||
" let v = vec![10, 20, 30];\n"
|
||||
" let mut iter = v.into_iter();\n"
|
||||
" 'outer: while let Some(x) = iter.next() {\n"
|
||||
" println!(\"x: {x}\");\n"
|
||||
" let mut i = 0;\n"
|
||||
" while i < x {\n"
|
||||
" println!(\"x: {x}, i: {i}\");\n"
|
||||
" i += 1;\n"
|
||||
" if i == 3 {\n"
|
||||
" break 'outer;\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"```"
|
||||
|
||||
#: src/control-flow/break-continue.md:28
|
||||
msgid ""
|
||||
|
Loading…
x
Reference in New Issue
Block a user