const
Constants are evaluated at compile time and their values are inlined wherever they are used:
Rust RFC Book によると、定数変数は使用時にインライン化されます。
コンパイル時に const
値を生成するために呼び出せるのは、const
とマークされた関数のみです。ただし、const
関数は実行時に呼び出すことができます。
Speaker Notes
- Mention that
const
behaves semantically similar to C++’sconstexpr
- 実行時に評価される定数が必要になることはあまりありませんが、静的変数を使用するよりも便利で安全です。