Skip to content

Commit

Permalink
io: add ReadBuf::inner_mut
Browse files Browse the repository at this point in the history
This returns the entire buffer as a `&mut [MaybeUninit<u8>]`, which may
be useful for building abstractions on top.
  • Loading branch information
sunshowers committed Jan 19, 2021
1 parent 5402c94 commit 7fd98b5
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tokio/src/io/read_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,25 @@ impl<'a> ReadBuf<'a> {
unsafe { mem::transmute::<&mut [MaybeUninit<u8>], &mut [u8]>(slice) }
}

/// Returns a mutable reference to the entire buffer, without ensuring that it has been fully
/// initialized.
///
/// The elements between 0 and `self.filled().len()` are filled, and those between 0 and
/// `self.initialized().len()` are initialized (and so can be transmuted to a `&mut [u8]`).
///
/// The caller of this method must ensure that these invariants are upheld. For example, if the
/// caller initializes some of the uninitialized section of the buffer, it must call
/// [`assume_init`](Self::assume_init) with the number of bytes initialized.
///
/// # Safety
///
/// The caller must not de-initialize portions of the buffer that have already been initialized.
/// This includes any bytes in the region marked as uninitialized by `ReadBuf`.
#[inline]
pub unsafe fn inner_mut(&mut self) -> &mut [MaybeUninit<u8>] {
self.buf
}

/// Returns a mutable reference to the unfilled part of the buffer without ensuring that it has been fully
/// initialized.
///
Expand Down

0 comments on commit 7fd98b5

Please sign in to comment.