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.
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
new(it should create an emptyReadBuf, but that is useless, I think)From<&'a mut [u8]> for ReadBuf<'a>to create a ReadBuf from a byte slice (rather thannew)From<&'a mut [MaybeUninit<u8>]> for ReadBuf<'a>to create a ReadBuf from a byte slice (rather thanuninit)Length functions
capacityfilled_len->lento matchVecetc.filled_len(usefilled().len())remaining(can usecapacity() - len()orunfilled().len())initialized_len(can useinitialized().len())Slicing functions
filled,initialized,unfilled,uninitialized, and mut variantsRemovefilledandfilled_mut, replace by implementingInto<&'a mut [u8]> for ReadBuf<'a>Initializing data
initialize_unfilledandinitialize_unfilled_to, unless these are super usefulassume_initMisc
clearandappendadd_filledset_filledtoassume_filled(to matchassume_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.