1

Is it possible to use an array of bits instead of an array of bytes in Rust like the C++ version below?

std::bitset<8> b2(42);          // [0,0,1,0,1,0,1,0]

I am sending packets over the network that have either a true or false value, so there is no need to use, for example, 34 bytes (could be even higher, up to 64000 bytes) when I can just use ((34 % 8) != 0 + 34 / 8 = 5) bytes.

I could just make a function (or crate) doing this job, but isn't it something that should already be part of the Rust library?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Antonin GAVREL
  • 9,682
  • 8
  • 54
  • 81

0 Answers0