Closed nolanderc closed 2 months ago
Thank you for this issue. It also summarizes some of my previous ideas. I wanted to only expose a &mut [MaybeUninit<u8>]
to users and let them write to it using the MaybeUninit::write_slice
method. Unfortunately, it's still unstable...
The only way to use
ReservedSpace
currently is to use thestd::io::Write
implementation. However, this assumes that the entire value can be written in one go. This prevents certain patterns, such as having a header in the value which contains the a checksum of the remaining bytes.There should be some mechanism to reference arbitrary bytes within the space. Some options (naming TBD):
fn written_bytes_mut(&mut self) -> &mut [u8]
. This is safe as the bytes are known to be initialized.fn zero_bytes_mut(&mut self) -> &mut [u8]
. This would mark the entire space as written.fn as_bytes_mut_uninit(&mut self) -> &mut [MaybeUninit<u8>]
. Can be used to write arbitrary data in any order. Needs a complementary method to mark them as written:unsafe fn assume_written(&mut self, count: usize)
, which isunsafe
because caller must guarantee that all bytes0..count
have been initialized.