[][src]Macro static_assertions::assert_eq_type

macro_rules! assert_eq_type {
    ($($xs:tt)+) => { ... };
}

Asserts that types are equal.

Examples

On stable Rust, using the macro requires a unique “label” when used in a module scope:

type A = u8;
type B = A;

assert_eq_type!(byte; u8, A, B);

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_eq_type!(u8, A, B);

This macro can also be used to compare types that involve lifetimes. Just use 'static in that case:

type Buf<'a> = &'a [u8];

assert_eq_type!(Buf<'static>, &'static [u8]);

The following produces a compilation failure because String and str do not refer to the same type:

This example deliberately fails to compile
assert_eq_type!(String, str);