Skip to content

Commit

Permalink
Merge pull request #188 from baby230211/fix/duplicate-words
Browse files Browse the repository at this point in the history
fix: remove duplicate words
  • Loading branch information
weihanglo authored Nov 27, 2023
2 parents 84f95c7 + 46b7a3e commit 443c09c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/ch19-05-macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

一個函式簽名必須宣告該函式需要的參數型別與數量。反觀巨集可以接收變動數量的參數:我們可以用一個參數呼叫 `println!("hello")` ,也可以是兩個參數的 `println!("hello {}", name)`。另外,巨集會在編譯器開始翻譯程式碼的意義之前展開。例如可以使用巨集實作一個特徵。這種事函式便無法做到,因為函式會在執行期呼叫,而特徵需要在編譯期就實作。

選擇實作巨集而不用函式也有缺點,巨集的定義比函式更加複雜,因為你是在寫寫 Rust 程式碼的 Rust 程式碼。就是因為這種間接迂迴的關係,一般情況下,相較於函式來說巨集的定義都更加難以閱讀、理解與維護。
選擇實作巨集而不用函式也有缺點,巨集的定義比函式更加複雜,因為你是在寫 Rust 的程式碼。就是因為這種間接迂迴的關係,一般情況下,相較於函式來說巨集的定義都更加難以閱讀、理解與維護。

另一個巨集和函式之間的重要的的差異,在一個檔案中想呼叫巨集,必須在作用域(scope)內定義或是將巨集帶到這個作用域,而反過來函式可以在任何地方定義與呼叫。

Expand Down

0 comments on commit 443c09c

Please sign in to comment.