PSA: You too can pack structs

PSA: You too can pack structs

Speaker: Nicola Papale


This is an introductory talk. It is aimed at people that are not familiar with struct packing.

Struct packing is useful in a variety of situation, being aware of it can help reduce code complexity and improve performance. Yet, I’ve come across many rust developers who aren’t familiar with struct packing.

This talk presents struct packing, and crates available on that people may not be aware of, but should really use.

I first introduce how rust layouts structs. Then I introduce motivating use cases. Then I show how it is possible to implement it by hand, then using bitflags. Then I introduce how C solves this. Then I explain the pitfalls of the C solution and hint at a “good” solution. Finally, I introduce the crates specialized in struct packing.

The crates in questions are:

The motivating use cases include:

I will mention #[repr(packed)] only as something not to do.


Technology & Community


Introductory and overview