diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-11-24 08:23:51 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-24 08:23:51 +0100 |
| commit | b8657093d6fe834af76bb28d5fd71dc67853112f (patch) | |
| tree | dc1c290712c4259e3c549be6802d2bf06f6d4fec | |
| parent | 41fe75ec6b824d51e5365098c4af9de45e5a2723 (diff) | |
| parent | 1fb00335df72fc3a05cd13a2bd5013f362d21177 (diff) | |
| download | rust-b8657093d6fe834af76bb28d5fd71dc67853112f.tar.gz rust-b8657093d6fe834af76bb28d5fd71dc67853112f.zip | |
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`?
| -rw-r--r-- | library/std/src/io/mod.rs | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index 260200115c8..c8507a956ff 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -556,6 +556,10 @@ where /// therefore, using something that implements [`BufRead`], such as /// [`BufReader`], will be more efficient. /// +/// Repeated calls to the reader use the same cursor, so for example +/// calling `read_to_end` twice on a [`File`] will only return the file's +/// contents once. It's recommended to first call `rewind()` in that case. +/// /// # Examples /// /// [`File`]s implement `Read`: |
