Skip to content

Commit

Permalink
Auto merge of rust-lang#103754 - SUPERCILEX:filled-mut, r=m-ou-se
Browse files Browse the repository at this point in the history
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#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
  • Loading branch information
bors committed Jul 11, 2023
2 parents e571544 + 050d5f6 commit 48a814d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions library/std/src/io/readbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down

0 comments on commit 48a814d

Please sign in to comment.