bytes icon indicating copy to clipboard operation
bytes copied to clipboard

Improve Buf / BufMut docs

Open carllerche opened this issue 6 years ago • 3 comments

It is not clear how these traits should be implemented when the byte storage is not in continuous memory.

carllerche avatar Jan 18 '18 18:01 carllerche

Yeah, we just run into an issue. For our datastructure that's not in continuous memory we implemented Buf trait. Each of the continuous pieces of this datastructure can be empty, and so Buf::bytes() might be empty. But if it happens that get_u8() is called when Buf::bytes() returns an empty slice then it panics i.e. get_u8() doesn't check if a slice is empty or not

StanislavGlebik avatar Jan 28 '19 16:01 StanislavGlebik

Do you have thoughts on how to improve the docs? I would :heart: a PR.

carllerche avatar Jan 28 '19 18:01 carllerche

Well, I have thoughts on the issue I encountered. In that particular case it's either a documentation issue because docs do not highlight that bytes() should not return an empty slice, or a problem in the code because get_*8 do not check if bytes() are empty. I'm happy to send a PR. IMHO, the latter solution is better.

For the BufMut @jsgf might have opinions on that.

StanislavGlebik avatar Jan 28 '19 20:01 StanislavGlebik