diff options
| author | Alex Saveau <saveau.alexandre@gmail.com> | 2022-10-29 22:56:51 -0700 |
|---|---|---|
| committer | Alex Saveau <saveau.alexandre@gmail.com> | 2022-10-29 23:16:33 -0700 |
| commit | 050d5f64e6d3a97d2685b7c6ba05a921ebb31fc2 (patch) | |
| tree | e4652d2e34f813124226151276545adc7eb6ef87 | |
| parent | 4827ceecb9ee9bc0508fecf7059bcc134ca187d0 (diff) | |
| download | rust-050d5f64e6d3a97d2685b7c6ba05a921ebb31fc2.tar.gz rust-050d5f64e6d3a97d2685b7c6ba05a921ebb31fc2.zip | |
Add BorrowedBuf::filled_mut
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
| -rw-r--r-- | library/std/src/io/readbuf.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/library/std/src/io/readbuf.rs b/library/std/src/io/readbuf.rs index 4800eeda022..1f3f80b9618 100644 --- a/library/std/src/io/readbuf.rs +++ b/library/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> { |
