macro_rules! assert_align_eq {
    ($x:ty, $($y:ty),+ $(,)?) => { ... };
}
Expand description

Asserts that the types’ alignments are equal.

This is useful when ensuring that pointer arithmetic is done correctly, or when FFI requires a type to have the same alignment as some foreign type.

Examples

A usize has the same alignment as any pointer type:

assert_align_eq!(usize, *const u8, *mut u8);

The following passes because [i32; 4] has the same alignment as i32:

assert_align_eq!([i32; 4], i32);

The following example fails to compile because i32x4 explicitly has 4 times the alignment as [i32; 4]:

#[repr(align(16))]
struct i32x4([i32; 4]);

assert_align_eq!(i32x4, [i32; 4]);