How does rust optimize bools in structs?

The title states the question.
If I have a struct like this:

struct Example {
   myBool1: bool,
   myBool2: bool,
   myBool3: bool,
   myBool4: bool

Does it compile into a u8 acting as a bitflag, does it just compile it as 4 u8s which can either be 1 or 0, or does it do something completely different?

That struct will take up four bytes, each either zero or one. It can't compile it down to a bitflag, because you must be to turn an &Example into an &bool pointing to any of the four booleans.


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.