fix(bytesbuf): correct put_bytes panic docs#496
Open
sandersaares wants to merge 1 commit into
Open
Conversation
BytesBuf::put_bytes documented an inapplicable panic condition (insufficient remaining capacity). Appending a BytesView is zero-copy and consumes no capacity, so its only failure mode is the total length exceeding usize::MAX; correct the docs accordingly. Also add comments to from_blocks/from_span_builders explaining why no overflow check is needed there: they reference exclusively owned memory, whose combined capacity is bounded by the virtual address space and cannot exceed usize::MAX. This bound only needs an explicit guard for BytesView, which references shared memory that may be aliased by multiple views. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
d4993fe to
375b4b5
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #496 +/- ##
=====================================
Coverage 99.9% 99.9%
=====================================
Files 336 336
Lines 24829 24829
=====================================
Hits 24818 24818
Misses 11 11 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR corrects the public documentation for BytesBuf::put_bytes to describe its actual panic condition (length/capacity overflow), reflecting that appending a BytesView is zero-copy and does not require remaining writable capacity in the buffer.
Changes:
- Update
BytesBuf::put_bytespanic docs to describe overflow (> usize::MAX) instead of “insufficient remaining capacity”. - Add clarifying comments in
BytesBuf::from_blocks/from_span_buildersexplaining why no overflow guard is required when aggregating exclusively ownedBlock/SpanBuildercapacity.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/bytesbuf/src/buf.rs | Adds explanatory comments about why overflow checks aren’t needed when aggregating exclusively owned capacity sources. |
| crates/bytesbuf/src/buf_put.rs | Fixes put_bytes panic documentation to match the real panic condition (overflow). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Vaiz
approved these changes
Jun 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
BytesBuf::put_bytesdocumented an inapplicable panic condition (insufficient remaining capacity). Appending aBytesViewis zero-copy and brings its own backing memory, so it never consumes buffer capacity; its only failure mode is the total length exceedingusize::MAX. The docs now state that.While investigating, I also confirmed the
usizebound only needs an explicit overflow guard on theBytesViewside (already present infrom_spans_reversed, documented onfrom_views/append/concat).BytesBuf::from_blocks/from_span_buildersoperate on exclusively owned memory (Block/SpanBuilder), whose combined capacity is bounded by the virtual address space and can never exceedusize::MAX. Added comments there explaining why no check is needed, contrasting withBytesView's shared, potentially aliased memory.