Skip to content

docs: clarify Buf::remaining contract - #858

Open
SatvikMishra08 wants to merge 1 commit into
tokio-rs:masterfrom
SatvikMishra08:docs/835-buf-remaining
Open

SatvikMishra08 wants to merge 1 commit into
tokio-rs:masterfrom
SatvikMishra08:docs/835-buf-remaining

Conversation

@SatvikMishra08

Copy link
Copy Markdown

Summary

Clarifies the Buf::remaining contract in rustdoc in response to #835.

When remaining() is less than usize::MAX, it is the exact number of bytes still readable before the buffer is exhausted. Implementers must not let remaining() change spontaneously while the buffer is only used through Buf, and after advance(cnt) (with cnt <= remaining()) the next remaining() must be old - cnt, except when the true length saturates at usize::MAX (e.g. oversized Buf::chain of clones).

Also notes that adapters such as BufMut::put rely on this for correctness.

Docs-only; no API or behavior change.

Fixes #835

Test plan

  • cargo doc --no-deps (no broken intra-doc links)
  • maintainer review of the wording vs. intended invariants

Document that remaining() is the exact unread length when below
usize::MAX, that it must not change spontaneously through Buf alone,
and how it interacts with advance (including usize::MAX saturation).

Fixes tokio-rs#835

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Contract clarification for Buf::remaining

1 participant