Skip to content

Commit 67491eb

Browse files
committedJul 20, 2015
Merge pull request #3 from cesarb/read_all
Explanations about the buffer contents
2 parents 894ab34 + 7cd058d commit 67491eb

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
 

‎text/0000-read-all.md

+24
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,30 @@ discard the stream anyways.
173173
Users who need finer control should use the `read` method directly, or
174174
when available use the `Seek` trait.
175175

176+
# About the buffer contents
177+
178+
This RFC proposes that the contents of the output buffer be undefined on
179+
an error return. It might be untouched, partially overwritten, or
180+
completely overwritten (even if less bytes could be read; for instance,
181+
this method might in theory use it as a scratch space).
182+
183+
Two possible alternatives could be considered: do not touch it on
184+
failure, or overwrite it with valid data as much as possible.
185+
186+
Never touching the output buffer on failure would make it much more
187+
expensive for the default implementation (which calls `read` in a loop),
188+
since it would have to read into a temporary buffer and copy to the
189+
output buffer on success. Any implementation which cannot do an early
190+
return for all failure cases would have similar extra costs.
191+
192+
Overwriting as much as possible with valid data makes some sense; it
193+
happens without any extra cost in the default implementation. However,
194+
for optimized implementations this extra work is useless; since the
195+
caller can't know how much is valid data and how much is garbage, it
196+
can't make use of the valid data.
197+
198+
Users who need finer control should use the `read` method directly.
199+
176200
# Naming
177201

178202
It's unfortunate that `write_all` used `WriteZero` for its `ErrorKind`;

0 commit comments

Comments
 (0)
Please sign in to comment.