const
Constants are evaluated at compile time and their values are inlined wherever they are used:
根据 Rust RFC Book 这些变量在使用时是内联 (inlined) 的。
在编译时只能调用标记为“const”的函数以生成“const”值。不过,可在运行时调用“const”函数。
Speaker Notes
- Mention that
const
behaves semantically similar to C++’sconstexpr
- 虽然需要使用在运行中求值的常量的情况并不是很常见,但是它是有帮助的,而且比使用静态变量更安全。