Today I was using an online chat bot (a well-known one) and exploring changes to my Rust code. The chat bot confidently told me that in Rust a Vec
of bool
is encoded as a single bit per bool
. I even asked if this was "truly" the case in Rust, as I was not familiar with this.
In Rust the Vec
type does not tend to have type-specific optimizations like for bool
. It is supposed to be simple. The chat bot explained that yes, in Rust a Vector of bools only requires 1 bit per bool
.
This is not correct. A bool
requires 1 byte in Rust, and 1 byte is 8 bits. Further online searches supported this—the chat bot was confidently wrong.
I created a test program that allocated 100 million bools in a Vec
, and then used the bools in an infinite loop. It required about 100000 kB, which means that about 1000 bools fit in 1 kB of memory. Which means that 1 bool
requires about 1 byte. There has to be some source of truth—and AI chat bots can be wrong.