Skip to content

Commit 8fff287

Browse files
committed
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 rust-lang/rust#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: rust-lang/libs-team#139
2 parents 64bee8c + 147bb2c commit 8fff287

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

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)