about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-07-11 19:07:11 +0000
committerbors <bors@rust-lang.org>2023-07-11 19:07:11 +0000
commit48a814deab50b59f803bc6c2af59a95eecd47362 (patch)
treea19fa2039abf012d6e711680fbf68f9dc5ec8bf9
parente571544f4448d35af55e5ea3f35b92a2e784944a (diff)
parent050d5f64e6d3a97d2685b7c6ba05a921ebb31fc2 (diff)
downloadrust-48a814deab50b59f803bc6c2af59a95eecd47362.tar.gz
rust-48a814deab50b59f803bc6c2af59a95eecd47362.zip
Auto merge of #103754 - SUPERCILEX:filled-mut, r=m-ou-se
Add back BorrowedBuf::filled_mut

This is useful if you want to do some processing on the bytes while still using the BorrowedBuf.

The API was removed in https://github.com/rust-lang/rust/pull/97015 with no explanation. The RFC also has it as part of its API, so this just seems like a mistake: [RFC](https://rust-lang.github.io/rfcs/2930-read-buf.html#:~:text=inline%5D%0A%20%20%20%20pub%20fn-,filled_mut,-(%26mut%20self))

ACP: https://github.com/rust-lang/libs-team/issues/139
-rw-r--r--library/std/src/io/readbuf.rs7
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> {