Skip to content

Conversation

@sandersaares
Copy link
Member

@sandersaares sandersaares commented Feb 11, 2026

Mission

  • Ensure that BytesView and BytesBuf expose slice memory block metadata as a first-class citizen whenever iterating through their slices.
  • Refactor BytesView and BytesBuf "get slices" methods to use iterators instead of "copy to array" style for more flexible API (user code can do the copy from iterator to array if it wants to).
  • Add Send + Sync bounds to memory block metadata to ensure that they do not cause futures to become !Send if references are stored (in practice, all foreseeable metadata types we expect to implement are going to be thread-safe immutable data).

This fills a gap in functionality (hard to access metadata for vectored writes into a BytesBuf), makes the API more flexible by preferring iterators and improves compatibility with metadata processing in futures.

BytesView API changes

The current situation is:

  • BytesView exposes .first_slice_meta() and .iter_slice_metas(), which are a good start but it is lacking an "iterate over slices and metas together" operation.
  • BytesView exposes .slices() and .io_slices() which copy the individual slices into arrays of slices. This is cumbersome because sometimes you just want an iterator, so the copy is unnecessary.

Change BytesView as follows:

  • The existing BytesView::iter_slice_metas() is removed.
  • The existing BytesView::io_slices() is removed.
  • The existing BytesView::slices() is removed.
  • We replace the last one with BytesView::slices() -> BytesViewSlices<'a>, which is an iterator that iterates over tuples of (slice, meta).

Expected usage (pseudocode):

for (data, meta) in bytes.slices() {
    ...
}

If the user wants to still copy the slices into an array, they can just fill the array in this loop.

We will not provide any replacement for .io_slices(). This was anyway a legacy function of dubious value. It remains available through bytes::Buf when the bytes-compat feature is enabled.

BytesBuf API changes

The current situation is:

  • BytesBuf exposes no memory block metadata at all about the slices it allows writes into! This is an important functionality gap.

Change BytesBuf as follows:

  • Add BytesBuf::first_unfilled_slice_meta().

Because BytesBuf only directly provides access to the first unfilled slice (intentionally), we do not need a mechanism to iterate through the metadatas (or slices) on BytesBuf itself.
However, it also provides concurrent access to multiple slices through the vectored write mechanism in BytesBufVectoredWrite.

Change BytesBufVectoredWrite as follows:

  • Rename iter_slices_mut() to just slices_mut() to simplify the name (as long as we are already making breaking changes).
  • Change the BytesBufRemaining returned from slices_mut() to iterate over tuples of (slice, meta) similar to what we did with BytesView.

@codecov
Copy link

codecov bot commented Feb 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.0%. Comparing base (cb9a395) to head (0885995).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #248   +/-   ##
=======================================
  Coverage   100.0%   100.0%           
=======================================
  Files         139      139           
  Lines        8440     8441    +1     
=======================================
+ Hits         8440     8441    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sandersaares sandersaares marked this pull request as ready for review February 12, 2026 07:55
@github-actions
Copy link

github-actions bot commented Feb 12, 2026

⚠️ Breaking Changes Detected


--- failure inherent_method_missing: pub method removed or renamed ---

Description:
A publicly-visible method or associated fn is no longer available under its prior name. It may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.46.0/src/lints/inherent_method_missing.ron

Failed in:
  BytesView::io_slices, previously in file /home/runner/work/oxidizer/oxidizer/target/semver-checks/git-origin_main/f885917ebe25f72912adf053ed432e64368785b1/crates/bytesbuf/src/view.rs:569
  BytesView::iter_slice_metas, previously in file /home/runner/work/oxidizer/oxidizer/target/semver-checks/git-origin_main/f885917ebe25f72912adf053ed432e64368785b1/crates/bytesbuf/src/view.rs:694
  BytesBufVectoredWrite::iter_slices_mut, previously in file /home/runner/work/oxidizer/oxidizer/target/semver-checks/git-origin_main/f885917ebe25f72912adf053ed432e64368785b1/crates/bytesbuf/src/buf.rs:995

--- failure method_parameter_count_changed: pub method parameter count changed ---

Description:
A publicly-visible method now takes a different number of parameters, not counting the receiver (self) parameter.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#fn-change-arity
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.46.0/src/lints/method_parameter_count_changed.ron

Failed in:
  bytesbuf::BytesView::slices now takes 0 parameters instead of 1, in /home/runner/work/oxidizer/oxidizer/crates/bytesbuf/src/view.rs:563

--- failure struct_missing: pub struct removed or renamed ---

Description:
A publicly-visible struct cannot be imported by its prior path. A `pub use` may have been removed, or the struct itself may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.46.0/src/lints/struct_missing.ron

Failed in:
  struct bytesbuf::BytesViewSliceMetas, previously in file /home/runner/work/oxidizer/oxidizer/target/semver-checks/git-origin_main/f885917ebe25f72912adf053ed432e64368785b1/crates/bytesbuf/src/view.rs:966

If the breaking changes are intentional then everything is fine - this message is merely informative.

Remember to apply a version number bump with the correct severity when publishing a version with breaking changes (1.x.x -> 2.x.x or 0.1.x -> 0.2.x).

@sandersaares sandersaares merged commit e675fdf into main Feb 12, 2026
27 checks passed
@sandersaares sandersaares deleted the u/sasaares/bytesbuf-expose-meta branch February 12, 2026 14:52
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.

3 participants