const
Constants are evaluated at compile time and their values are inlined wherever they are used:
Gemäß dem Rust RFC Book werden diese bei der Verwendung eingefügt (inlined upon use).
Only functions marked const
can be called at compile time to generate const
values. const
functions can however be called at runtime.
Speaker Notes
- Mention that
const
behaves semantically similar to C++'sconstexpr
- Es kommt nicht sehr häufig vor, dass man eine zur Laufzeit ausgewertete Konstante benötigt, aber es ist hilfreich und sicherer als die Verwendung einer statischen.