Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking issue for `Read::initializer` #42788
Comments
sfackler
added
B-unstable
T-libs
labels
Jun 21, 2017
Mark-Simulacrum
added
the
C-tracking-issue
label
Jul 22, 2017
This comment has been minimized.
This comment has been minimized.
|
I'm personally no longer sold on the infrastructure that we've got here I think. I was initially hoping that we'd have some safe way of working with these APIs and such, but in the end it all turned up unsafe. In light of all that I'd personally advocate for much simpler API: impl Read {
#[inline]
unsafe fn may_read_buffer(&self) -> bool { true }
}I don't think the complexity we have today is worth the cost currently, and I'd imagine that we could start making abstractions like: fn initialize_buffer_for(r: &Read, buf: &mut [u8]) {
// ...
} |
This comment has been minimized.
This comment has been minimized.
|
I wrote a tiny library for reading into uninitialized buffers: https://crates.io/crates/buffer/ Maybe its ideas could be adapted for the standard library. The following is safe code using the library:
Adoption of something like this in the standard library would probably also help with adoption by third party crates, see e.g. carllerche/mio#628. |
This comment has been minimized.
This comment has been minimized.
|
An alternative to the current API is to go along the path that unsafe trait ReadUninit: Read {}With specialization landing, anyone who cares to can take advantage of impl<T: Read> ReadBuf for T {
fn read_buf<B: BufMut>(&mut self, buf: &mut B) {
self.read(buf.zeroed())
}
}
impl<T: ReadUninit> ReadBuf for T {
fn read_buf<B: BufMut>(&mut self, buf: &mut B) {
self.read(buf.bytes())
}
} |
This comment has been minimized.
This comment has been minimized.
|
That's incompatible with trait objects which are used pretty heavily with Read in particular. |
This comment has been minimized.
This comment has been minimized.
|
Specialization is incompatible with trait objects? |
This comment has been minimized.
This comment has been minimized.
|
If I have a |
carllerche
referenced this issue
Apr 2, 2018
Closed
cpu load by prepare_uninitialized_buffer in async_read of tokio-io #269
Thomasdezeeuw
referenced this issue
Aug 11, 2018
Merged
Deprecate uninitialized in favor of a new MaybeUninit type #1892
This comment has been minimized.
This comment has been minimized.
|
@RalfJung suggested a function that takes |
sfackler commentedJun 21, 2017
Implemented in #42002.