I worked on tungstenite code which uses std::io::Read::read into a BytesMut buffer.
One issue with this is to provide the full capacity to the Read impl BytesMut::resize is called on each read to zero fill the capacity so that it is safely usable.
This isn't optimal as it may require re-writing zeros across say a larger buffer on small reads. I was wondering if there is prior art on solving this issue?
Potential solutions:
- Use
set_len, but this is not sound as Read impls could read the buffer before writing to it. ❌
- Write a variant of
BytesMut that always zeroes its capacity. It would then be sound to use set_len in this case. Does anything like this already exist?
I worked on tungstenite code which uses
std::io::Read::readinto aBytesMutbuffer.One issue with this is to provide the full capacity to the
ReadimplBytesMut::resizeis called on each read to zero fill the capacity so that it is safely usable.This isn't optimal as it may require re-writing zeros across say a larger buffer on small reads. I was wondering if there is prior art on solving this issue?
Potential solutions:
set_len, but this is not sound asReadimpls could read the buffer before writing to it. ❌BytesMutthat always zeroes its capacity. It would then be sound to use set_len in this case. Does anything like this already exist?