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

Please provide a read_buf_exact helper #7127

Open
joshtriplett opened this issue Jan 26, 2025 · 2 comments · May be fixed by #7130
Open

Please provide a read_buf_exact helper #7127

joshtriplett opened this issue Jan 26, 2025 · 2 comments · May be fixed by #7130
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-io Module: tokio/io

Comments

@joshtriplett
Copy link

read_buf allows reading into any BufMut, such as an uninitialized buffer; however, it requires dealing with partial reads. read_exact avoids having to deal with partial reads, but it only accepts an initialized buffer.

Please consider adding a read_buf_exact that accepts any BufMut and avoids having to deal with partial reads.

@joshtriplett joshtriplett added A-tokio Area: The main tokio crate C-feature-request Category: A feature request. labels Jan 26, 2025
@Darksonn Darksonn added the M-io Module: tokio/io label Jan 27, 2025
@Darksonn
Copy link
Contributor

Seems reasonable enough to me. I would be happy to see this.

@maminrayej maminrayej linked a pull request Jan 27, 2025 that will close this issue
@maminrayej
Copy link
Member

@joshtriplett I worked on implementing read_buf_exact in #7130, but encountered an issue with resizable buffers like Vec. I'd like to hear your thoughts on this.

Since these buffers have infinite capacity, it's a misuse of the function to call it like read_buf_exact(&mut vec). So the function signature should be something like read_buf_exact(buff, len) so the expected amount is explicitly passed to the function, but this makes it a less attractive API and feature to be added to AsyncReadExt.
We could also put this under tokio-util, next to read_buf, but then it's a harder to find API.

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

Successfully merging a pull request may close this issue.

3 participants