Compile-time assertions to ensure that invariants are met.
All assertions within this crate are performed at compile-time. This allows for finding errors quickly and early when it comes to ensuring certain features or aspects of a codebase.
This crate is available on crates.io and can be used by adding the
following to your project's
[dependencies] static_assertions = "0.2.5"
and this to your crate root:
#[macro_use] extern crate static_assertions;
Very thorough examples are provided in the docs for each individual macro. Failure case examples are also documented.
Due to implementation details, some macros can only be used normally from within the context of a function. To use these macros in other contexts, a unique label must be provided.
// error: expected item after attributes const_assert!(true == true);
This can be fixed via:
const_assert!(label; true == true);
This issue can be followed here. Feedback and potential solutions are welcome!
Asserts that a given configuration is set.
Asserts that types are equal in size.
Asserts that values pointed to are equal in size.
Asserts that values are equal in size.
Asserts that the type has the given fields.
Asserts that the type implements the given traits.
Asserts that the traits are object-safe.
Asserts that constant expressions evaluate to
Asserts that constants are equal in value.