Skip to content

Commit b865709

Browse files
authored
Rollup merge of #116807 - seanlinsley:patch-2, r=thomcc
Improve rewind documentation The persistent use of an internal cursor for readers is expected for buffer data types that aren't read all at once, but for files it leads to the confusing situation where calling `read_to_end` on the same file handle multiple times only returns the contents of the file for the first call. This PR adds a note to the documentation clarifying that in that case, `rewind()` must first be called. I'm unsure if this is the right location for the docs update. Maybe it should also be duplicated on `File`?
2 parents 41fe75e + 1fb0033 commit b865709

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

library/std/src/io/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,10 @@ where
556556
/// therefore, using something that implements [`BufRead`], such as
557557
/// [`BufReader`], will be more efficient.
558558
///
559+
/// Repeated calls to the reader use the same cursor, so for example
560+
/// calling `read_to_end` twice on a [`File`] will only return the file's
561+
/// contents once. It's recommended to first call `rewind()` in that case.
562+
///
559563
/// # Examples
560564
///
561565
/// [`File`]s implement `Read`:

0 commit comments

Comments
 (0)