[−][src]Macro static_assertions::assert_impl
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:
ⓘThis example is not tested
#![feature(underscore_const_names)] assert_impl!(u32, Copy, Send); fn main() { assert_impl!(&str, Into<String>); }
Raw pointers cannot be sent between threads safely:
ⓘThis example deliberately fails to compile
assert_impl!(*const u8, Send);