Commit Graph
1 Commits
Author SHA1 Message Date
rifuki 89f4d133ba io: read lines as bytes so a partial line survives an I/O error (#8400)
`Lines` accumulated into a `String`, so a partial line interrupted by an
I/O error could not be kept when it ended mid multi-byte character. The
next poll then tripped `debug_assert!(output.is_empty())`, or
underflowed `vector.len() - num_bytes_read` in `put_back_original_data`,
which panics in release builds too on the `.expect` below it.

`Lines` now holds a single `buf: Vec<u8>` and calls
`read_until_internal` directly the way `Split` does, converting to
`String` only once a whole line is available.

An `InvalidData` error now carries the utf-8 error itself rather than a
fixed string. `Lines` owns the line, so it hands over the whole
`FromUtf8Error` and the caller can still recover the bytes; `read_line`
and `read_to_string` have to put those bytes back into the caller's
`String`, so they carry `Utf8Error` instead.

`read_line_internal` has no callers outside `read_line.rs` and is now
private.
2026-09-04 11:33:54 +00:00