Crate qed

Crate qed 

Source
Expand description

Compile time assertions.

This crate contains compile time assertion macros used for maintaining safety invariants or limiting platform support. If the assertion is false, a compiler error is emitted.

§Examples

qed::const_assert!(usize::BITS >= u32::BITS);
qed::const_assert_eq!("Veni, vidi, vici".len(), 16);
qed::const_assert_ne!('∎'.len_utf8(), 1);
qed::const_assert_matches!(NonZeroU8::new(42), Some(nz) if nz.get() == 42);

Assertion failures will result in a compile error:

qed::const_assert!("non-empty string".is_empty());

Macros§

const_assert
Asserts that a boolean expression is true at compile time.
const_assert_bytes_has_no_nul
Asserts that a byte slice does not contain any NUL (\0) bytes.
const_assert_eq
Asserts that two expressions are equal to each other (using PartialEq) at compile time.
const_assert_matches
Asserts that an expression matches any of the given patterns at compile time.
const_assert_ne
Asserts that two expressions are not equal to each other (using PartialEq) at compile time.
const_assert_size_eq
Asserts that two types have the same size at compile time.
const_cstr_from_bytes
Construct a const CStr from the given bytes at compile time and assert that the given bytes are a valid CStr (NUL terminated with no interior NUL bytes).
const_cstr_from_str
Construct a const CStr from the given str at compile time and assert that the given str bytes are a valid CStr (NUL terminated with no interior NUL bytes).
lossless_cast_u32_to_usize
Cast a u32 to usize at runtime with a compile time assert that the cast is lossless and will not overflow.