rust-lang / futures-rs

Zero-cost asynchronous programming in Rust
https://rust-lang.github.io/futures-rs/
Apache License 2.0
5.35k stars 619 forks source link

read_to_string error handling is inconsistent with std #2702

Open dfoxfranke opened 1 year ago

dfoxfranke commented 1 year ago

AsyncReadExt::read_to_string leaves buf empty if it encounters invalid UTF-8. This is inconsistent with the behavior of std::io::Read::read_to_string, which will truncate it to original length (i.e. leave it unchanged).

Relatedly, the performance of this method could be improved. Currently it validates the entire string; it is only necessary to validate the newly-read portion since the original portion is already guaranteed to be valid.