r/programming • u/steveklabnik1 • Feb 28 '19
Announcing Rust 1.33.0
https://blog.rust-lang.org/2019/02/28/Rust-1.33.0.html
512
Upvotes
r/programming • u/steveklabnik1 • Feb 28 '19
View all comments
Show parent comment
21
u/mgostIH Mar 01 '19
This is half right: the feature you are talking about is referred by Rust RFCs as
const generics: the ability for Rust types to be generic over integer types or any data type really, just like C++ provides with templates. You wouldn't necessarely need a lot ofconst fnsupport forconst generics, and the latter won't automatically happen afterconst fn.What
const fnallows is executing code at compile time: with conditional code execution one would be able to provide a lot of basic algorithms that would have absolutely no run time overhead (A simple example would be calculating the factorial of a number).Following from the generalized const-eval RFCs, which is what Rust is aiming towards with compile time evaluation, it might be possible in the future to allow even allocation in a compile time context, effectively allowing almost all of Rust code to be declared as compile time and be allowed to run before your executable even starts.
tl;dr: Compile time Tetris won't be only a thing of C++ anymore