Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add BorrowedBuf::buf* accessor functions for getting the original buffer #98962

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions library/std/src/io/readbuf.rs
Original file line number Diff line number Diff line change
@@ -246,4 +246,25 @@ impl<'a> ReadBuf<'a> {
pub fn initialized_len(&self) -> usize {
self.initialized
}

/// Returns the buffer
#[inline]
pub fn buf(&self) -> &[MaybeUninit<u8>] {
&*self.buf
}

/// Returns the buffer
///
/// # Safety
/// You must not write unitialized bytes to positions less than `self.initialized_len()`
#[inline]
pub unsafe fn buf_mut(&mut self) -> &mut [MaybeUninit<u8>] {
self.buf
}

/// Returns the buffer
#[inline]
pub fn into_buf(self) -> &'a mut [MaybeUninit<u8>] {
self.buf
}
}