I've realized that I have possibly been assuming a stronger invariant for the return value of Buf::remaining than exists, and would appreciate clarification.
Currently the documentation states:
- the method
Returns the number of bytes between the current position and the end of the buffer
- the return value is never less than the length of the current chunk
- the return value must not change unless the length of the buffer is somehow modified or the buffer is advanced
One reading of this implies a strong invariant: "remaining() must always return the exact number of bytes that would be read before the end if the whole buffer were read right now".
Another reading (hopefully a wrong one! this would be very inconvenient!) could be that the apparent remaining length of the buffer may change any time it is advanced, so long as it appears to be at least as long as the current chunk, and that it need not always be exactly the number of bytes that would be read before the end immediately after the call. The documentation of Buf::advance does not specify how the return value of remaining should change after advance is called.
Can you confirm that the stronger invariant must hold by contract? Should we strengthen the language in the trait method docs, or am I jumping at shadows here?
I've realized that I have possibly been assuming a stronger invariant for the return value of
Buf::remainingthan exists, and would appreciate clarification.Currently the documentation states:
Returns the number of bytes between the current position and the end of the bufferOne reading of this implies a strong invariant: "
remaining()must always return the exact number of bytes that would be read before the end if the whole buffer were read right now".Another reading (hopefully a wrong one! this would be very inconvenient!) could be that the apparent remaining length of the buffer may change any time it is advanced, so long as it appears to be at least as long as the current chunk, and that it need not always be exactly the number of bytes that would be read before the end immediately after the call. The documentation of
Buf::advancedoes not specify how the return value ofremainingshould change afteradvanceis called.Can you confirm that the stronger invariant must hold by contract? Should we strengthen the language in the trait method docs, or am I jumping at shadows here?