For both [bool; 128] and Vec w/ capacity 128, ignoring the header, is it safe to assume that both takes 16 bytes ? If so, where is this documented ?
The core issue here is whether a bool is stored as a u8 or if Rust is somehow packing 8 bool's into 1 u8.
Bool is stored as u8, since we can address individual bools, but can't address anything less then byte.
2 Likes
bool takes one byte:
Boolean Type in The Rust Reference
An object with the boolean type has a size and alignment of 1 each.
2 Likes
kaj
June 11, 2021, 11:56am
4
If you need to store 128 booleans in 16 bytes, you can but you have to do some bitshifting to acecss the individual "booleans". Either you can implement that by hand, or you can use e.g. https://crates.io/crates/bitvec to do it for you.
3 Likes
system
Closed
September 9, 2021, 2:31pm
6
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.