Skip to content

Contract clarification for Buf::remaining #835

Description

@mumbleskates

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:

  1. the method Returns the number of bytes between the current position and the end of the buffer
  2. the return value is never less than the length of the current chunk
  3. 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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions