assert_not_impl_any in static_assertions - Rust (original) (raw)
Macro assert_not_impl_any
macro_rules! assert_not_impl_any {
($x:ty: <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false">(</mo></mrow><annotation encoding="application/x-tex">(</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span></span></span></span>t:path),+ $(,)?) => { ... };
}
Expand description
Asserts that the type does not implement any of the given traits.
This can be used to ensure types do not implement auto traits such asSend and Sync, as well as traits with blanket impls.
This macro causes a compilation failure if any of the provided individual traits are implemented for the type. If you want to check that a combination of traits is not implemented you should invoke assert_not_impl_all!instead. For single traits both macros behave the same.
§Examples
If u32
were to implement Into
conversions for usize
and for u8
, the following would fail to compile:
assert_not_impl_any!(u32: Into<usize>, Into<u8>);
This is also good for simple one-off cases:
assert_not_impl_any!(&'static mut u8: Copy);
The following example fails to compile since u32
can be converted intou64
even though it can not be converted into a u16
:
assert_not_impl_any!(u32: Into<u64>, Into<u16>);