Skip to content

Proposal: add AsyncReadExt::by_ref #2616

@jorgecarleitao

Description

@jorgecarleitao

Hi,

When reading a known number of bytes from futures::io::ReadAsync, it is useful to use the idiom

let mut a = vec![];
a.try_reserve(length0)?;
reader
    .by_ref()
    .take(length0 as u64)
    .read_to_end(a)
    .await?;

a.clear();
a.try_reserve(length1)?;
reader
    .by_ref()
    .take(length1 as u64)
    .read_to_end(a)
    .await?;

however, this is currently not possible because by_ref does not exist like Read::by_ref. This makes it impossible to implement the idiom above.

The proposal is to add such method. Alternatively, any way of doing the above? ^^

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions