Usage of inline const
for static assertions
#235
Labels
C-proposal
A proposal of some kind, and a request for comments.
E-help-wanted
Call for participation: Help is requested to fix this issue.
E-medium
Medium difficulty. Experience needed to fix: Intermediate.
P-low
Low priority.
What
Rust 1.79 brought inline
const
expressions.These can be used to conditionally make static assertions (among other things).
Why
Turns runtime panics into compile time errors.
Where/How
Certain runtime panics can be replaced with these new inline
const
expressions, e.g.:cuprate/storage/database/src/env.rs
Lines 126 to 128 in 929d19c
Can be turned into:
This will make calling
resize()
from database backends that shouldn't be callingresize_map()
in the first place to fail at compile time instead of at runtime.The
const
expression will only be evaluated ifresize()
is called, e.g.:This program will only fail if
f::<false>()
is called. It is commented out (not called) so it compiles fine.The text was updated successfully, but these errors were encountered: