feat(bytesbuf): add BytesBuf::split_off_remaining#286
Merged
sandersaares merged 5 commits intomainfrom Feb 26, 2026
Merged
Conversation
Add split_off_remaining() and split_off_remaining_checked() methods to BytesBuf that detach a specified number of bytes of remaining capacity from the end of the buffer, returning a new empty BytesBuf that owns that capacity. This is a utility function that can be beneficial in test code and in specialized situations where cutting buffers to specific capacities is useful (e.g. to pre-partition capacity across multiple buffers from a single reservation). Also adds the internal SpanBuilder::split_off_available() helper that enables splitting a single span builder's unfilled capacity.
martintmk
approved these changes
Feb 25, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #286 +/- ##
=======================================
Coverage 100.0% 100.0%
=======================================
Files 141 141
Lines 8664 8715 +51
=======================================
+ Hits 8664 8715 +51 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ZacWalk
approved these changes
Feb 26, 2026
… capacity Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ZacWalk
approved these changes
Feb 26, 2026
martin-kolinek
approved these changes
Feb 26, 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.
Summary
Add
split_off_remaining()andsplit_off_remaining_checked()methods toBytesBufthat detach a specified number of bytes of remaining (unfilled) capacity from the end of the buffer, returning a new emptyBytesBufthat owns that capacity. The original buffer's filled data is unaffected.This is a utility function that can be beneficial in test code and in specialized situations where cutting buffers to specific capacities is useful — for example, to pre-partition capacity across multiple buffers from a single reservation.
API
Follows the established crate pattern of panicking + checked variant pairs (like
consume/consume_checkedandbegin_vectored_write/begin_vectored_write_checked). The naming follows thesplit_offconvention from the standard library (Vec::split_off,String::split_off).Changes
span_builder.rs: Added internalSpanBuilder::split_off_available()helper that splits off unfilled capacity from the end of a span builder into a newSpanBuildersharing the same memory block.buf.rs: Addedsplit_off_remaining()andsplit_off_remaining_checked()onBytesBuf. The implementation drains complete empty span builders from the end and, if needed, splits a partially-used builder's available capacity.