Crate static_assertions [−] [src]
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.
Usage
This crate is available on crates.io and can be used by adding the
following to your project's Cargo.toml
:
[dependencies]
static_assertions = "0.2.5"
and this to your crate root:
#[macro_use] extern crate static_assertions;
Examples
Very thorough examples are provided in the docs for each individual macro. Failure case examples are also documented.
Limitations
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!
Macros
assert_cfg |
Asserts that a given configuration is set. |
assert_eq_size |
Asserts that types are equal in size. |
assert_eq_size_ptr |
Asserts that values pointed to are equal in size. |
assert_eq_size_val |
Asserts that values are equal in size. |
assert_fields |
Asserts that the type has the given fields. |
assert_impl |
Asserts that the type implements the given traits. |
assert_obj_safe |
Asserts that the traits are object-safe. |
const_assert |
Asserts that constant expressions evaluate to |
const_assert_eq |
Asserts that constants are equal in value. |