You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rollup merge of rust-lang#137107 - thaliaarchi:io-optional-methods/cursors, r=joboet
Override default `Write` methods for cursor-like types
Override the default `io::Write` methods for cursor-like types to provide more efficient versions.
Writes to resizable containers already write everything, so implement `write_all` and `write_all_vectored` in terms of those. For fixed-sized containers, cut out unnecessary error checking and looping for those same methods.
| `impl Write for T` | `vectored` | `all` | `all_vectored` | `fmt` |
| ------------------------------- | ---------- | ----- | -------------- | ------- |
| `&mut [u8]` | Y | Y | new | |
| `Vec<u8>` | Y | Y | new | rust-lang#137762 |
| `VecDeque<u8>` | Y | Y | new | rust-lang#137762 |
| `std::io::Cursor<&mut [u8]>` | Y | new | new | |
| `std::io::Cursor<&mut Vec<u8>>` | Y | new | new | rust-lang#137762 |
| `std::io::Cursor<Vec<u8>>` | Y | new | new | rust-lang#137762 |
| `std::io::Cursor<Box<[u8]>>` | Y | new | new | |
| `std::io::Cursor<[u8; N]>` | Y | new | new | |
| `core::io::BorrowedCursor<'_>` | new | new | new | |
Tracked in rust-lang#136756.
# Open questions
Is it guaranteed by `Write::write_all` that the maximal write is performed when not everything can be written? Its documentation describes the behavior of the default implementation, which writes until a 0-length write is encountered, thus implying that a maximal write is expected. In contrast, `Read::read_exact` declares that the contents of the buffer are unspecified for short reads. If it were allowed, these cursor-like types could bail on the write altogether if it has insufficient capacity.
0 commit comments