Open
Description
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 emptyReadBuf
, but that is useless, I think) - Should implement
From<&'a mut [u8]> for ReadBuf<'a>
to create a ReadBuf from a byte slice (rather thannew
) - Should implement
From<&'a mut [MaybeUninit<u8>]> for ReadBuf<'a>
to create a ReadBuf from a byte slice (rather thanuninit
)
Length functions
- Keep
capacity
filled_len
->len
to matchVec
etc.- remove
filled_len
(usefilled().len()
) - remove
remaining
(can usecapacity() - len()
orunfilled().len()
) - remove
initialized_len
(can useinitialized().len()
)
Slicing functions
- Keep
filled
,initialized
,unfilled
,uninitialized
, and mut variants Removefilled
andfilled_mut
, replace by implementingInto<&'a mut [u8]> for ReadBuf<'a>
Initializing data
- Remove
initialize_unfilled
andinitialize_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
andappend
- Remove
add_filled
- Rename
set_filled
toassume_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.