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

Documentation for io::Read::read's return value #70360

Closed
bedax opened this issue Mar 24, 2020 · 3 comments
Closed

Documentation for io::Read::read's return value #70360

bedax opened this issue Mar 24, 2020 · 3 comments
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@bedax
Copy link

bedax commented Mar 24, 2020

As far as I know File uses libc::read on unix for its Read implementation. The read method returns the amount of bytes that were read to the given buffer. libc::read's man page says the following:

It is not an error if this number is smaller than the number of bytes requested; this may happen for example because fewer bytes are actually available right now (maybe because we were close to end-of-file, or because we are reading from a pipe, or from a terminal), or because read() was interrupted by a signal.

I think the documentation for io::Read doesn't currently make it clear that the returned value can be less than the buffer size, even when the reader is not at the end of the stream. While this behaviour may seem obvious to anyone familiar with libc, it should still be documented, as it's not obvious for those coming from other languages, and it can be important in some cases.

@Dylan-DPC-zz
Copy link

@bedax thanks for the issue. Would you be ready to submit a PR that makes it clearer?

@bedax
Copy link
Author

bedax commented Mar 24, 2020

Hi @Dylan-DPC, absolutely, I'll give it a go and submit it soon.

@csmoe csmoe added A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Mar 25, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue May 9, 2020
Better documentation for io::Read::read() return value

Aims to provide the clarity requested in rust-lang#70360
@ThibsG
Copy link
Contributor

ThibsG commented May 10, 2020

I believe this issue can be closed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants