-
Notifications
You must be signed in to change notification settings - Fork 626
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
Add AsyncRead::poll_read_buf based on RFC 2930 #2209
Comments
Also Personally I think this should wait for an unstable |
The RFC was merged, so seems it makes sense to start getting this in now? |
I still think there's no point in copy-pasting EDIT: I also see an in-progress implementation, so I don't think it'll be too long till it lands on nighly. |
Isn't the version from Tokio inconsistent with the rfc, as they use |
Well that means we can only ship it on nightly and not on stable, which seems unfortunate but fine I guess. |
|
This is likely material for a meeting, but the premise that we may issue breaking changes to
If we expect we can implement this for For clarity, this is what I'm currently discussing: // ✔ The `Read` baseline, `read_buf` extends the base trait
trait Read {
fn read(&mut self, buf: &mut [u8]) -> Result<usize>;
fn read_buf(&mut self, buf: &mut ReadBuf<'_>) -> io::Result<()>;
}
// ✔ Similar to `Read`, `read_buf` extends the `AsyncRead` base trait
trait AsyncRead {
fn poll_read(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8]) -> Poll<Result<usize>>;
fn poll_read_buf(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut ReadBuf<'_>) -> Poll<Result<usize>>;
}
// ❌ Breaks `AsyncRead`, usage patterns no longer shared with `Read`
trait AsyncRead {
// unclear how to read into `&mut [u8]`
fn read(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut ReadBuf<'_>) -> Poll<Result<usize>>;
} As what we're designing here is expected to serve as the foundation for future stdlib extensions, we should emphasize long-term consistency over limited short-term convenience. The more usage patterns align, the easier it'll be to evolve the stdlib over time. And for Rust programmers to internalize how to use it. Which is why I am strongly in favor of introducing |
I agree with @yoshuawuyts and really hope we can keep the existing I think it is great that the RFC already figured out how to do this in a non breaking way, so we should leverage that as much as we can. |
I also agree with @yoshuawuyts. I believe the goal is to get |
We have one guaranteed breaking change coming up, when It could even be a two-step process with a transition phase where we add a second default-implemented method as you outlined, during the time For clarity my expectation would be to keep the naming consistent (this is something I consider to be a bug in Tokio 0.3's translation, I don't see any discussion of it in the PR and it might be related to unfortunate conflicts with trait AsyncRead {
fn poll_read_buf(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut ReadBuf<'_>) -> Poll<Result<()>>;
} The answer to the "unclear how to read into
This is a "Future Possibility", there's no guarantee that it is going to be implemented. If we just avoid the issue in the first place then there's no need to solve it at all. One of my hopes is that as soon as |
@Nemo157 thanks for clarifying! — I'm glad we're in agreement on the shape and name of the API. A deviation in usage patterns between the two APIs was my primary concern, and that's been alleviated. On the question of which method should be implementable by default on
@Nemo157 I suspect we could take the same approach here as what we're looking to do for |
No, this is breaking change. If you have code that imports only |
If this is possible I'm on board with going the non-breaking route, just if we have an upcoming breaking change I think we should consider hard on whether it's worth going to |
(Marked as blocked until implemented in std. The API proposed in RFC has some issues and is likely to change when it is actually implemented in std.) |
FYI, it looks like the initial implementation of ReadBuf landed a few days ago in nightly rust-lang/rust#81156. The tracking ticket rust-lang/rust#78485 is still open though, so no idea when it'll stabilize. |
I found that std's |
Add the
poll_read_buf
method toAsyncRead
based on the API proposed by rust-lang/rfcs#2930 (tracking issue: rust-lang/rust#78485).This replaces the existing read-initializer API, but it's not yet stable, so maybe it needs to added as an unstable feature.
The text was updated successfully, but these errors were encountered: