Expand description
Compile time utilities.
§Compile Time Assertions
By default, dungeon_cell will generate compile time panics if
an assertion made with this module fails. These panics will happen when rustc
attempts to instantiate associated const values. This does not happen when
running cargo check. They will only happen when actually fully building a project.
This limitation is because generics can’t be used in normal const expressions
(see the tracking issue for generic_const_exprs).
The resulting compiler errors don’t have any information on where the
failing assert is located. The environment variable
DUNGEON_CELL_RUNTIME_CHECKS can be enabled (it can have any value) while
building dungeon_cell to have asserts made with this module generate runtime
panics with a backtrace instead.
Example of enabling the environment variable using a .config/cargo.toml.
[env]
DUNGEON_CELL_RUNTIME_CHECKS = "true"§Example Assertion Failure
use dungeon_cell::compile_time::{SmallerOrEqualTo, UsizeAssert};
use dungeon_cell::Size;
SmallerOrEqualTo::<u16, Size<1>>::assert();Output:
error[E0080]: evaluation of `<compile_time::SmallerOrEqualTo<u16, layout::Size<1>> as compile_time::UsizeAssert>::FAILED` failed
--> src/compile_time.rs:40:26
|
40 | const FAILED: bool = do_usize_const_assert::<Self>(PanicMode::Monomorphized);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at '
assertion failed: size of type T <= 1, type T has size = 2.
This error happens after monomorphization so the location of the code that caused
this to happen is not known. Add the `DUNGEON_CELL_RUNTIME_CHECKS` environment
variable when compiling to enable runtime panics with a backtrace.
', src/compile_time.rs:40:26Structs§
- Alignment
Smaller OrEqual To - Size
Smaller OrEqual To - Assert size of
Tis smaller or equal to given size.
Enums§
- Comparison
- Type of comparison.
Traits§
- Usize
Assert - Compile time evaluable assert for
usizevalues.
Functions§
- const_
transmute ⚠ - Transmute for const contexts.
- const_
usize_ assert - Const form of
UsizeAssert::assert().