-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update bytes to v0.6 #2323
Update bytes to v0.6 #2323
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,6 +2,7 @@ use std::cell::Cell; | |||||||||||||||
use std::cmp; | ||||||||||||||||
use std::fmt; | ||||||||||||||||
use std::io::{self, IoSlice}; | ||||||||||||||||
use std::mem::MaybeUninit; | ||||||||||||||||
|
||||||||||||||||
use bytes::{Buf, BufMut, Bytes, BytesMut}; | ||||||||||||||||
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; | ||||||||||||||||
|
@@ -188,7 +189,11 @@ where | |||||||||||||||
if self.read_buf_remaining_mut() < next { | ||||||||||||||||
self.read_buf.reserve(next); | ||||||||||||||||
} | ||||||||||||||||
let mut buf = ReadBuf::uninit(&mut self.read_buf.bytes_mut()[..]); | ||||||||||||||||
let dst = self.read_buf.bytes_mut(); | ||||||||||||||||
// Safety: `dst` may include uninitialized memory, but `ReadBuf` will | ||||||||||||||||
// never uninitialize memory that has already been initialized. | ||||||||||||||||
let dst = unsafe { &mut *(dst as *mut _ as *mut [MaybeUninit<u8>]) }; | ||||||||||||||||
let mut buf = ReadBuf::uninit(dst); | ||||||||||||||||
match Pin::new(&mut self.io).poll_read(cx, &mut buf) { | ||||||||||||||||
Comment on lines
+192
to
197
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An alternative to all of this (which avoids the scary-looking pointer cast that @Urhengulas was concerned about) is to just use
Suggested change
That would mean adding a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That seems like a good solution! And this is a useful function which can't be found in the docs... (code: https://github.com/tokio-rs/tokio/blob/master/tokio-util/src/lib.rs#L67-L134). |
||||||||||||||||
Poll::Ready(Ok(_)) => { | ||||||||||||||||
let n = buf.filled().len(); | ||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That line looks threatening..
Can you please add a comment saying what it is doing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't actually know what it's doing ;)
I borrowed this from https://github.com/tokio-rs/tokio/blob/d78655337a68bded305782a8a8b4ac7be42aa6a7/tokio/src/io/util/read_buf.rs#L53-L55, which was the only updated use of
ReadBuf::uninit
I could find.I would appreciate feedback from someone who understands these APIs better than I do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seanmonstar ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But let's see who introduced it 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tokio-rs/tokio#3121
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, added a comment summarizing that discussion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect 😄