From 147bb2c5926d85b8f7acce39c871c9c9d15b3d03 Mon Sep 17 00:00:00 2001 From: Alex Saveau Date: Sat, 29 Oct 2022 22:56:51 -0700 Subject: [PATCH] Add BorrowedBuf::filled_mut Signed-off-by: Alex Saveau --- std/src/io/readbuf.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/std/src/io/readbuf.rs b/std/src/io/readbuf.rs index 4800eeda0..1f3f80b96 100644 --- a/std/src/io/readbuf.rs +++ b/std/src/io/readbuf.rs @@ -99,6 +99,13 @@ impl<'data> BorrowedBuf<'data> { unsafe { MaybeUninit::slice_assume_init_ref(&self.buf[0..self.filled]) } } + /// Returns a mutable reference to the filled portion of the buffer. + #[inline] + pub fn filled_mut(&mut self) -> &mut [u8] { + // SAFETY: We only slice the filled part of the buffer, which is always valid + unsafe { MaybeUninit::slice_assume_init_mut(&mut self.buf[0..self.filled]) } + } + /// Returns a cursor over the unfilled part of the buffer. #[inline] pub fn unfilled<'this>(&'this mut self) -> BorrowedCursor<'this> {