Skip to content

Should IoSliceMut::advance() be used when impl std::io::Read::read_vectored()? #128669

Open
@zh-jq-b

Description

@zh-jq-b

As of io_slice_advance is stable since 1.81, the following asserting may won't work if the users use IoSliceMut::advance in their impl of Read trait.

fn what_to_read<R>(reader: R)
where
    R: Read,
{
    let mut b1 = [0u8; 16];
    let mut b2 = [0u8; 32];

    let mut iov = [IoSliceMut::new(&mut b1), IoSliceMut::new(&mut b2)];
    let nr = reader.read_vectored(&mut iov).unwrap();

    if nr > 0 {
        assert_eq!(b1[0], iov[0][0]);
    }
    if nr >= b1.len() {
        assert_eq!(iov[0].len(), b1.len());
    }
}

It is unclear that whether the returned size of read_vectored is the real read data size, or the valid buffer size in the passed &mut [IoSliceMut<'_>].
Please clarify that so Read implementations can do the correct thing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsA-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`C-discussionCategory: Discussion or questions that doesn't represent real issues.T-libsRelevant to the library team, which will review and decide on the PR/issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions