Skip to content

ReadBuf's API #94741

Description

@nrc

cc #78485

ReadBuf is unstable, part of the read-buf feature. I believe the API might be improved by some of the following ways (I've grouped methods by theme):

Construction

  • remove new (it should create an empty ReadBuf, but that is useless, I think)
  • Should implement From<&'a mut [u8]> for ReadBuf<'a> to create a ReadBuf from a byte slice (rather than new)
  • Should implement From<&'a mut [MaybeUninit<u8>]> for ReadBuf<'a> to create a ReadBuf from a byte slice (rather than uninit)

Length functions

  • Keep capacity
  • filled_len -> len to match Vec etc.
  • remove filled_len (use filled().len())
  • remove remaining (can use capacity() - len() or unfilled().len())
  • remove initialized_len (can use initialized().len())

Slicing functions

  • Keep filled, initialized, unfilled, uninitialized, and mut variants
  • Remove filled and filled_mut, replace by implementing Into<&'a mut [u8]> for ReadBuf<'a>

Initializing data

  • Remove initialize_unfilled and initialize_unfilled_to, unless these are super useful
    • rationale, getting unfilled slice is easy, initialising is easy, so it seems the only benefit is tracking this
  • keep assume_init

Misc

  • Keep clear and append
  • Remove add_filled
  • Rename set_filled to assume_filled (to match assume_init)

The current API is documented at https://doc.rust-lang.org/nightly/std/io/struct.ReadBuf.html

This issue continues a discussion from Zulip (https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/ReadBuf.20API), there was not much discussion relevant to the points above.

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

    A-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions