We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
try_reserve_exact
try_with_capacity
std::fs::read
1 parent ac17c34 commit 0dec3feCopy full SHA for 0dec3fe
library/std/src/fs.rs
@@ -285,8 +285,7 @@ pub fn read<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> {
285
fn inner(path: &Path) -> io::Result<Vec<u8>> {
286
let mut file = File::open(path)?;
287
let size = file.metadata().map(|m| m.len() as usize).ok();
288
- let mut bytes = Vec::new();
289
- bytes.try_reserve_exact(size.unwrap_or(0))?;
+ let mut bytes = Vec::try_with_capacity(size.unwrap_or(0))?;
290
io::default_read_to_end(&mut file, &mut bytes, size)?;
291
Ok(bytes)
292
}
0 commit comments