Skip to content
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

AsyncRead, AsyncWrite updates using async_fn_in_trait #6173

Closed
tgross35 opened this issue Nov 28, 2023 · 1 comment
Closed

AsyncRead, AsyncWrite updates using async_fn_in_trait #6173

tgross35 opened this issue Nov 28, 2023 · 1 comment
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-io Module: tokio/io

Comments

@tgross35
Copy link

tgross35 commented Nov 28, 2023

Is your feature request related to a problem? Please describe.

AFIT will be stable in 1.75 rust-lang/rust#115822. I think this allows for simplification of some of the traits in tokio::io and elsewhere.

Describe the solution you'd like

E.g. AsyncRead::poll_read should be able to have an aync fn signature and return Result<usize>, rather than taking cx and returning a Poll.

This will make it easier for users to make use of the trait directly, as opposed to going through other tokio function calls.

Describe alternatives you've considered

I do not know what the exact signatures would look like. This would of course be a MSRV breaking change so it may need a feature flag.

@tgross35 tgross35 added A-tokio Area: The main tokio crate C-feature-request Category: A feature request. labels Nov 28, 2023
@Darksonn Darksonn added the M-io Module: tokio/io label Nov 28, 2023
@Darksonn
Copy link
Contributor

This isn't going to happen. The AsyncRead/AsyncWrite traits cannot be changed due to backwards compatibility.

Besides, even if we could change it, we wouldn't want to because using async_fn_in_trait for these traits would remove some of their features:

  • You would no longer be able to read and write at the same time, because the read/write futures mutably borrow the IO resource. E.g., the tokio::io::split utility becomes impossible.
  • You would give up cancellation safety, so you could no longer safely read or write in a tokio::select!.
  • You would give up dynamic dispatch, so you could no longer use Pin<Box<dyn AsyncRead>>.

Possibly the methods on the Ext traits could be replaced with async_fn_in_trait, but that's a different matter and would mostly only affect how the documentation is rendered.

This would of course be a MSRV breaking change so it may need a feature flag.

Our MSRV policy would prevent us from adopting this for six months, but it's not just an MSRV-breaking change. It's a full breaking change that would require a 2.0 release of Tokio.

@Darksonn Darksonn closed this as not planned Won't fix, can't repro, duplicate, stale Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-io Module: tokio/io
Projects
None yet
Development

No branches or pull requests

2 participants