Assertions to ensure correct assumptions about constants, types, and more.
All checks provided by 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. These macros are especially important when exposing a public API that requires types to be the same size or implement certain traits.
[dependencies] static_assertions = "1.1.0"
and this to your crate root (
#[macro_use] extern crate static_assertions;
When using Rust 2018 edition, the following shorthand can help if
#[macro_use] is undesirable.
extern crate static_assertions as sa; sa::const_assert!(true);
Very thorough examples are provided in the docs for each individual macro. Failure case examples are also documented.
for an exhaustive list of what has changed from one version to another.
This project is made freely available (as in free beer), but unfortunately not all beer is free! So, if you would like to buy me a beer (or coffee or more), then consider supporting my work that's benefited your project and thousands of others.
Asserts that a given configuration is set.
Asserts that types are equal in alignment.
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 all of the given traits.
Asserts that the type implements any of the given traits.
Asserts that the type implements exactly one in a set of traits.
Asserts that the type does not implement all of the given traits.
Asserts that the type does not implement any of the given traits.
Asserts that the traits support dynamic dispatch (object-safety).
Asserts that the trait is a child of all of the other traits.
Asserts that the trait is a parent of all of the other traits.
Asserts that all types in a list are equal to each other.
Asserts that all types are not equal to each other.
Asserts that constant expressions evaluate to
Asserts that constants are equal in value.
Asserts that constants are not equal in value.