File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -231,7 +231,9 @@ fn initial_buffer_size(file: &File) -> usize {
231
231
/// Read the entire contents of a file into a bytes vector.
232
232
///
233
233
/// This is a convenience function for using [`File::open`] and [`read_to_end`]
234
- /// with fewer imports and without an intermediate variable.
234
+ /// with fewer imports and without an intermediate variable. It pre-allocates a
235
+ /// buffer based on the file size when available, so it is generally faster than
236
+ /// reading into a vector created with `Vec::new()`.
235
237
///
236
238
/// [`File::open`]: struct.File.html#method.open
237
239
/// [`read_to_end`]: ../io/trait.Read.html#method.read_to_end
@@ -270,7 +272,9 @@ pub fn read<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> {
270
272
/// Read the entire contents of a file into a string.
271
273
///
272
274
/// This is a convenience function for using [`File::open`] and [`read_to_string`]
273
- /// with fewer imports and without an intermediate variable.
275
+ /// with fewer imports and without an intermediate variable. It pre-allocates a
276
+ /// buffer based on the file size when available, so it is generally faster than
277
+ /// reading into a string created with `String::new()`.
274
278
///
275
279
/// [`File::open`]: struct.File.html#method.open
276
280
/// [`read_to_string`]: ../io/trait.Read.html#method.read_to_string
You can’t perform that action at this time.
0 commit comments