Skip to content

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

Closed

Description

@bedax

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.

Activity

  1. Dylan-DPC-zz commented on Mar 24, 2020

    @Dylan-DPC-zz

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

  2. bedax commented on Mar 24, 2020

    @bedax
    Author

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

  3. added
    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools
    T-libs-api[DEPRECATED; DO NOT USE]
    on Mar 25, 2020
  4. added a commit that references this issue on May 9, 2020
  5. ThibsG commented on May 10, 2020

    @ThibsG
    Contributor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsT-libs-api[DEPRECATED; DO NOT USE]

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions