Skip to content

Commit 050d5f6

Browse files
committed
Add BorrowedBuf::filled_mut
Signed-off-by: Alex Saveau <[email protected]>
1 parent 4827cee commit 050d5f6

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

library/std/src/io/readbuf.rs

+7
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ impl<'data> BorrowedBuf<'data> {
9999
unsafe { MaybeUninit::slice_assume_init_ref(&self.buf[0..self.filled]) }
100100
}
101101

102+
/// Returns a mutable reference to the filled portion of the buffer.
103+
#[inline]
104+
pub fn filled_mut(&mut self) -> &mut [u8] {
105+
// SAFETY: We only slice the filled part of the buffer, which is always valid
106+
unsafe { MaybeUninit::slice_assume_init_mut(&mut self.buf[0..self.filled]) }
107+
}
108+
102109
/// Returns a cursor over the unfilled part of the buffer.
103110
#[inline]
104111
pub fn unfilled<'this>(&'this mut self) -> BorrowedCursor<'this> {

0 commit comments

Comments
 (0)