節錄:Rust 程式設計語言

通用

  • crate:原始碼檔案的集合,編譯出來的執行檔 (binary) 是一個 crate,函式庫 (library) 也是一個 crate。Cargo.toml 中的 dependencies 都是一個 crate。
  • prelude

    在預設情況下,Rust 會將一些在標準函式庫定義的型別引入每個程式的作用域中。這樣的集合稱為 prelude。如果你想使用的型別不在 prelude 的話,你需要顯式(explicit)地使用 use 陳述式(statement)將該型別引入作用域。std::io 函式庫能提供一系列實用的功能,這包含接收使用者輸入的能力。 — Ch. 2

語法相關

  • associated function:關聯函式,是針對型別實作的函式。如:String::new::new 中的 :: 語法代表 newString 型別的關聯函式。
  • placeholderprintln!("你的猜測數字:{guess}"); 中的大括號 {} 是一個 placeholder
  • marco:巨集,函式帶有驚嘆號 !
  • moduleuse std::io; 中的 io 就是一個 module。
  • trait:特徵,use rand::Rng; 中的 Rng 就是一個 trait。 — Ch. 10
  • 列舉 (enumerations; enum),每一種狀態都稱為 變體 (variants)
  • 可以使用 match 來決定 enum 中的 variants 下一步要做什麼。match 由 ==分支 (arms) 組成,每個分支包含一個模式 (pattern)==。 — Ch. 18
  • shadowing:遮蔽,重複使用變數,常常拿來將一個數值的型別轉換成另一個型別。 — Ch. 3
  • attribute:屬性,如:#[derive(Debug)]

參考資料