There is currently no way to specify alignment, but it is definitely desirable and useful. It is covered by issue # 33626 and its RFC Problem .
The current work to force alignment of some Foo structure should be as large as alignment of some type T to include a field of type [T; 0] [T; 0] , the size of which is zero, and therefore differently affect the behavior of the structure, for example, struct Foo { data: A, more_data: B, _align: [T; 0] } struct Foo { data: A, more_data: B, _align: [T; 0] } .
At night, this can be combined with SIMD types to get a certain high alignment, because they have an alignment equal to their size (well, the next power of two), for example
#[repr(simd)] struct SixteenBytes(u64, u64); struct Foo { data: A, more_data: B, _align: [SixteenBytes; 0] }
source share