Skip to content

Sketch: Add std adapters#8049

Draft
Kixunil wants to merge 1 commit intotokio-rs:masterfrom
Kixunil:std-adapters
Draft

Sketch: Add std adapters#8049
Kixunil wants to merge 1 commit intotokio-rs:masterfrom
Kixunil:std-adapters

Conversation

@Kixunil
Copy link
Copy Markdown

@Kixunil Kixunil commented Apr 15, 2026

I felt like I could better express myself by making a PR than trying to explain it in an issue, so here's a draft. If you agree with inclusion of this feature I will add the Read/BufRead impls and tests.

Motivation

Some functions are specifically designed to take in objects implementing std::io traits while guaranteeing that they don't lose state when WouldBlock is present (as opposed to e.g. write_all which does lose the state). Those function could thus be used to construct futures but it requires some boilerplate.

Solution

This PR adds a few utility adapters to help reduce the boilerplate by implementing the vast majority of it. The consumer of these adapters can pass a writer and a fairly simple closure to a method to obtain a Future which will process the desired operation.

I'm seeking feedback here and will update the PR as needed.

Some functions are specifically designed to take in objects implementing
`std::io` traits while guaranteeing that they don't lose state when
`WouldBlock` is present (as opposed to e.g. `write_all` which does lose
the state). Those function could thus be used to construct futures but
it requires some boilerplate.

This commit adds a few utility adapters to help reduce the boilerplate
by implementing the vast majority of it. The consumer of these adapters
can pass a writer and a fairly simple closure to a method to obtain a
`Future` which will process the desired operation.
@github-actions github-actions bot added the R-loom-util Run loom tokio-util tests on this PR label Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

R-loom-util Run loom tokio-util tests on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant