3 ms·
Const values are inlined at compile time wherever they are used. Const functions let you run code to define const values. This code will be run at compile time
by mden 6y ago
Const values are inlined at compile time wherever they are used.
Const functions let you run code to define const values. This code will be run at compile time before the const values are inlined.
For example let's say you have a constant for PI but you need 2*PI. You could do the multiplication in const context, meaning the multiplication will happen during compilation and not execution. Slowly more and more of the language is becoming usable in const context so more advanced things can be done during compile time.
- colejohnson66 6y agoWell, if you need `2*PI`, there’s now `f32::TAU` and `f64::TAU` :) You’re still correct though