-
Notifications
You must be signed in to change notification settings - Fork 24
翻譯drop和const and static #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The head ref may contain hidden characters: "\u7FFB\u8B6FDrop"
Changes from all commits
0c93aab
59b31ea
51d7bd6
c4012e9
49fa6e1
4272868
11552ab
f0fa478
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,7 @@ expression-oriented | 表達式導向 | | |
| expression statements | 表達陳述式 | | ||
| extensions | 擴充功能 | | ||
| handle | 控制代碼 | 參考:[維基百科][handle]、[MSDN][handle_2] | ||
| hash | 哈希/散列 | | ||
| heap | 堆積 | 參考:[維基百科][heap] | ||
| fault | 錯誤 | | ||
| formalization | 正規化 | | ||
|
|
@@ -58,6 +59,8 @@ inheritance | 繼承 | | |
| language feature | 語言特徵 | 參考:[中華民國資訊學會][language feature] | ||
| library | 函式庫 | 參考:[維基百科][library] | ||
| lifetimes | 生命週期 | | ||
| linker | 連接器 | | ||
| linking | 連接 | | ||
| loop | 迴圈、循環 | 參考:[維基百科][loop] | ||
| macro | 巨集 | 參考:[維基百科][macro] | ||
| main function | 主函式 | 參考:[維基百科][main function] | ||
|
|
@@ -81,13 +84,15 @@ pointer | 指標 | 參考:[維基百 | |
| polymorphism | 多型 | 參考:[維基百科][polymorphism] | ||
| primitive type | 基本型別 | 參考:[維基百科][primitive type] | ||
| reference | 參照、參考 | 參考:[維基百科][reference] | ||
| root | 根 | | ||
| round bracket | 圓括號 | 參考:[維基百科][bracket] | ||
| scope | 有效範圍 | | ||
| semantics | 語意 | | ||
| segment | 區段 | 參考:[維基百科][segment] | ||
| segmentation fault | 記憶體區段錯誤 | 參考:[維基百科][segmentation fault] | ||
| shadowing | 遮蔽 | | ||
| signed integer | 帶號整數 | 參考:[維基百科][integer] | ||
| shell | shell命令 | | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| square bracket | 方括號 | 參考:[維基百科][bracket] | ||
| stack | 堆疊 | 參考:[維基百科][stack] | ||
| statements | 陳述式 | | ||
|
|
@@ -188,10 +193,7 @@ crates | | | |
| dependencies | | | ||
| destructuring let | | 用於存取 tuple | ||
| fully-strict | | | ||
| hash | | | ||
| import | | | ||
| linker | | | ||
| linking | | | ||
| master | | git branch | ||
| mata | | | ||
| metaprogramming | | | ||
|
|
@@ -203,8 +205,6 @@ prelude | | 預先載入的函式 | |
| profiles | | | ||
| regression | | | ||
| repository | | | ||
| root | | | ||
| shell | | | ||
| slices | | 其他資料結構的參考 | ||
| tabs | | | ||
| target triple | | | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,8 +28,8 @@ | |
| * [Trait Objects](trait-objects.md) | ||
| * [Closures](closures.md) | ||
| * [Universal Function Call Syntax](ufcs.md) | ||
| * [Crates and Modules](crates-and-modules.md) | ||
| * [`const` and `static`](const-and-static.md) | ||
| * [箱與模塊](crates-and-modules.md) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 在一些簡體版本的譯本中已經把Rust語言中的Crate翻譯為包裝箱了。所以要不要採納這種譯法?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 如果把crate翻譯為箱的話,那麼downstream crate就可以順理成章的翻譯為衍生箱 |
||
| * [常量與靜態量](const-and-static.md) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| * [Attributes](attributes.md) | ||
| * [`type` aliases](type-aliases.md) | ||
| * [Casting between types](casting-between-types.md) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,56 +1,46 @@ | ||
| % `const` and `static` | ||
| % 常量與靜態量 | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 同上,建議翻為 |
||
|
|
||
| Rust has a way of defining constants with the `const` keyword: | ||
| 在Rust語言中定義常量可以使用 `const` 關鍵字: | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 建議把 |
||
|
|
||
| ```rust | ||
| const N: i32 = 5; | ||
| ``` | ||
|
|
||
| Unlike [`let`][let] bindings, you must annotate the type of a `const`. | ||
| 你必須明確指定一個 `const` 的型別,這和使用 [`let`][let] 關鍵字進行綁定並不相同。 | ||
|
|
||
| [let]: variable-bindings.html | ||
|
|
||
| Constants live for the entire lifetime of a program. More specifically, | ||
| constants in Rust have no fixed address in memory. This is because they’re | ||
| effectively inlined to each place that they’re used. References to the same | ||
| constant are not necessarily guaranteed to refer to the same memory address for | ||
| this reason. | ||
| 常量作用於整個程式的生命週期。實際上,在Rust語言中常量在在內存中並沒有確定的地址,它們會被內聯到所有被使用的地方。因此對於同一個常量的引用並不能確保您引用的是同一個內存地址內的數據。 | ||
|
|
||
| # `static` | ||
|
|
||
| Rust provides a ‘global variable’ sort of facility in static items. They’re | ||
| similar to constants, but static items aren’t inlined upon use. This means that | ||
| there is only one instance for each value, and it’s at a fixed location in | ||
| memory. | ||
| 在Rust語言中,“全局變量”是以靜態量的形式體現的。靜態量與常量是類似的,只不過在靜態量被使用時不發生內聯。換句話說,每一個靜態量都只有一個實體,並且位於內存中唯一確定的位置。 | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 一般我們會把 |
||
|
|
||
| Here’s an example: | ||
| 這裡有一道例題: | ||
|
|
||
| ```rust | ||
| static N: i32 = 5; | ||
| ``` | ||
|
|
||
| Unlike [`let`][let] bindings, you must annotate the type of a `static`. | ||
| 你必須明確指定一個 `static` 的型別,這和使用 [`let`][let] 關鍵字進行綁定並不相同。 | ||
|
|
||
| Statics live for the entire lifetime of a program, and therefore any | ||
| reference stored in a constant has a [`'static` lifetime][lifetimes]: | ||
| 靜態量作用於整個程序的生命週期,所以任何儲蓄在常量中的引用都有 [靜態量生命週期][lifetimes]: | ||
|
|
||
| ```rust | ||
| static NAME: &'static str = "Steve"; | ||
| ``` | ||
|
|
||
| [lifetimes]: lifetimes.html | ||
|
|
||
| ## Mutability | ||
| ## 可變性 | ||
|
|
||
| You can introduce mutability with the `mut` keyword: | ||
| 當您使用 `mut` 關鍵字的時候可以引入可變性: | ||
|
|
||
| ```rust | ||
| static mut N: i32 = 5; | ||
| ``` | ||
|
|
||
| Because this is mutable, one thread could be updating `N` while another is | ||
| reading it, causing memory unsafety. As such both accessing and mutating a | ||
| `static mut` is [`unsafe`][unsafe], and so must be done in an `unsafe` block: | ||
| 正因為它這種可變性導致一個線程正在修改變量`N`的時候,可能有另一個線程正在讀取它。這樣一來,內存就處於不安全的狀態。因此無論是修改一個`static mut`,還是讀取一個`static mut` 都是 [不安全的][unsafe], 所以它必須在 `unsafe` 區塊中才能操作: | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| ```rust | ||
| # static mut N: i32 = 5; | ||
|
|
@@ -64,23 +54,20 @@ unsafe { | |
|
|
||
| [unsafe]: unsafe.html | ||
|
|
||
| Furthermore, any type stored in a `static` must be `Sync`, and may not have | ||
| a [`Drop`][drop] implementation. | ||
| 更進一步的說,任何儲蓄在 `static` 中的型別都必須實現 `Sync`, 而且不能實現 [`Drop`][drop]。 | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| [drop]: drop.html | ||
|
|
||
| # Initializing | ||
| # 初始化 | ||
|
|
||
| Both `const` and `static` have requirements for giving them a value. They may | ||
| only be given a value that’s a constant expression. In other words, you cannot | ||
| use the result of a function call or anything similarly complex or at runtime. | ||
| 無論 `const` 還是 `static` 都需要被賦予一個值,且只能被賦予常數表達式的值。 換句話說,您不能使用一個函數的返回值或者任何相似的復合值對它賦值,也不能在程式運行的過程中賦值。 | ||
|
|
||
| # Which construct should I use? | ||
| > 譯者注:賦值的行為被稱之為初始化。 | ||
|
|
||
| Almost always, if you can choose between the two, choose `const`. It’s pretty | ||
| rare that you actually want a memory location associated with your constant, | ||
| and using a const allows for optimizations like constant propagation not only | ||
| in your crate but downstream crates. | ||
| # 我應該選擇使用哪一種構造? | ||
|
|
||
| 當您無所謂選擇哪個的絕大多數時候就選擇 `const`。 您只要極少數情況需要關心常量映射在內存中的地址,而且使用 `const` 允許您在自己的箱和衍生箱中像常數擴展那樣優化它。 | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
建議新增
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 同樣,在北京是沒有辦法打開維基百科的網站的 |
||
|
|
||
| > 譯者注:Rust語言中的常量相當於C語言中的#define | ||
|
|
||
| > *commit 9eda98a* | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
此處在台灣一般保留原文 hash 或稱為 雜湊 (故 Hash Table 有人稱為 雜湊表)。
Ref: https://zh.wikipedia.org/zh-tw/%E6%95%A3%E5%88%97
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我淚流滿面的表示自己在北京是打不開維基百科的