Skip to content

Commit

Permalink
io: expand on de-initialization of ReadBuf (#3035)
Browse files Browse the repository at this point in the history
  • Loading branch information
Darksonn authored Oct 24, 2020
1 parent ce173fd commit a95378a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions tokio/src/io/read_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use std::mem::{self, MaybeUninit};
/// This type is a sort of "double cursor". It tracks three regions in the
/// buffer: a region at the beginning of the buffer that has been logically
/// filled with data, a region that has been initialized at some point but not
/// yet logically filled, and a region at the end that is fully uninitialized.
/// The filled region is guaranteed to be a subset of the initialized region.
/// yet logically filled, and a region at the end that may be uninitialized.
/// The filled region is guaranteed to be a subset of the initialized region.
///
/// In summary, the contents of the buffer can be visualized as:
///
Expand All @@ -20,6 +20,10 @@ use std::mem::{self, MaybeUninit};
/// [ filled | unfilled ]
/// [ initialized | uninitialized ]
/// ```
///
/// It is undefined behavior to de-initialize any bytes from the uninitialized
/// region, since it is merely unknown whether this region is uninitialized or
/// not, and if part of it turns out to be initialized, it must stay initialized.
pub struct ReadBuf<'a> {
buf: &'a mut [MaybeUninit<u8>],
filled: usize,
Expand Down Expand Up @@ -115,6 +119,7 @@ impl<'a> ReadBuf<'a> {
/// # 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 unfilled_mut(&mut self) -> &mut [MaybeUninit<u8>] {
&mut self.buf[self.filled..]
Expand Down

0 comments on commit a95378a

Please sign in to comment.