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 ec8992d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tokio/src/io/read_buf.rs
Expand Up @@ -113,6 +113,18 @@ 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.
///
/// # 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>] {
&mut 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 ec8992d

Please sign in to comment.