Skip to content

Commit

Permalink
Shrink unsafe regions
Browse files Browse the repository at this point in the history
  • Loading branch information
sfackler committed Dec 8, 2023
1 parent 39e7b5d commit 668e5db
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,14 @@ where
ctx: &mut Context<'_>,
buf: &mut ReadBuf<'_>,
) -> Poll<io::Result<()>> {
// SAFETY: read_uninit does not de-initialize the buffer and guarantees that the first nread
// bytes are initialized.
self.with_context(ctx, |s| unsafe {
match cvt(s.read_uninit(buf.unfilled_mut()))? {
self.with_context(ctx, |s| {
// SAFETY: read_uninit does not de-initialize the buffer.
match cvt(s.read_uninit(unsafe { buf.unfilled_mut() }))? {
Poll::Ready(nread) => {
buf.assume_init(nread);
// SAFETY: read_uninit guarantees that nread bytes have been initialized.
unsafe {
buf.assume_init(nread);
}
buf.advance(nread);
Poll::Ready(Ok(()))
}
Expand Down

0 comments on commit 668e5db

Please sign in to comment.