forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#137107 - thaliaarchi:io-optional-methods/cu…
…rsors, 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.
- Loading branch information
Showing
2 changed files
with
146 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters