Skip to content

Commit 654204f

Browse files
authored
Rollup merge of #109022 - tmiasko:read-buf-exact, r=dtolnay
read_buf_exact: on error, all read bytes are appended to the buffer Guarantee that when `read_buf_exact` returns, all bytes read will be appended to the buffer. Including the case when the operations fails. The motivating use case are operations on a non-blocking reader. When `read_buf_exact` fails with `ErrorKind::WouldBlock` error, the operation can be resumed at a later time.
2 parents 462e7e7 + c21f1d0 commit 654204f

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

library/std/src/io/mod.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -823,8 +823,22 @@ pub trait Read {
823823

824824
/// Read the exact number of bytes required to fill `cursor`.
825825
///
826-
/// This is equivalent to the [`read_exact`](Read::read_exact) method, except that it is passed a [`BorrowedCursor`] rather than `[u8]` to
827-
/// allow use with uninitialized buffers.
826+
/// This is similar to the [`read_exact`](Read::read_exact) method, except
827+
/// that it is passed a [`BorrowedCursor`] rather than `[u8]` to allow use
828+
/// with uninitialized buffers.
829+
///
830+
/// # Errors
831+
///
832+
/// If this function encounters an error of the kind [`ErrorKind::Interrupted`]
833+
/// then the error is ignored and the operation will continue.
834+
///
835+
/// If this function encounters an "end of file" before completely filling
836+
/// the buffer, it returns an error of the kind [`ErrorKind::UnexpectedEof`].
837+
///
838+
/// If any other read error is encountered then this function immediately
839+
/// returns.
840+
///
841+
/// If this function returns an error, all bytes read will be appended to `cursor`.
828842
#[unstable(feature = "read_buf", issue = "78485")]
829843
fn read_buf_exact(&mut self, mut cursor: BorrowedCursor<'_>) -> Result<()> {
830844
while cursor.capacity() > 0 {

0 commit comments

Comments
 (0)