Is there a fieldalignment package (like in Golang)? Do we need it with Rust?

I'm coming from golang.

In Golang there is a fieldalignment project which aligns fields for a better performances (Saving a Third of Our Memory by Re-ordering Go Struct Fields | Lane's Blog).

Is in Rust something similar?

It's needed? Or the compiler aligns fields itself for better performances?

The layout of all non-#[repr(C)] types is unspecified exactly for this reason. I do recall seeing that the compiler performs some sort of field reordering for making structs smaller.

Here's a small playground that demonstrates field reordering.


Indeed. Rust has been reordering struct fields to reduce padding for years now. See


Or here's a prose writeup about it:


What a pleasure this language and what a pleasure this community of wonderful people! Thank you so much!

I choose the first answer as the solution, for the speed.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.