Macro static_assertions::assert_impl
source · macro_rules! assert_impl {
($($xs:tt)+) => { ... };
}
Expand description
Asserts that the type implements the given traits.
This can be used to ensure types implement auto traits such as Send
and
Sync
, as well as traits with blanket impl
s.
Examples
On stable Rust, using the macro requires a unique “label” when used in a module scope:
assert_impl!(str; String, Send, Sync, From<&'static str>);
assert_impl!(vec; &'static [u8], Into<Vec<u8>>);
The labeling limitation is not necessary if
compiling on nightly Rust with the nightly
feature enabled:
ⓘ
#![feature(underscore_const_names)]
assert_impl!(u32, Copy, Send);
fn main() {
assert_impl!(&str, Into<String>);
}
Raw pointers cannot be sent between threads safely:
ⓘ
assert_impl!(*const u8, Send);