Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

值

以下列出一些基本的內建型別,以及適用於各型的字面常量的語法。

類型常值
帶號整數i8、i16、i32、i64、i128、isize-10、0、1_000、123_i64
非帶號整數u8、u16、u32、u64、u128、usize0、123、10_u16
浮點數f32、f643.14、-10.0e20、2_f32
萬國碼純量值char'a'、'α'、'∞'
布林值booltrue、false

型別的寬度如下:

  • iN、uN 和 fN 的寬度為 N 位元
  • isize 和 usize 等同於指標的寬度
  • char 寬度為 32 位元
  • bool 寬度為 8 位元
This slide should take about 5 minutes.

除此之外,還有一些其他語法:

  • 數字中的底線全都可以省略,寫出來只是為了方便閱讀。換句話說,1_000 可以寫成 1000 (或 10_00),而 123_i64 則可寫成 123i64。