字面量
数字字面值可以通过添加类型后缀进行类型标注。例如,要指定字面值 42
的类型为 i32
,可以写成 42i32
。
无后缀数字字面值的类型取决于其使用方式。如果没有约束,编译器将对整数使用 i32
,对浮点数使用 f64
。
前面的代码中使用了一些尚未解释的概念。为了满足迫不及待的读者,这里简要说明如下:
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