diff options
| author | Fluid <90795031+fluiderson@users.noreply.github.com> | 2025-05-18 09:54:57 +0300 |
|---|---|---|
| committer | Fluid <90795031+fluiderson@users.noreply.github.com> | 2025-05-18 09:54:57 +0300 |
| commit | 0dec3fee34c5044f68579fedfa6882e0f69ff2cf (patch) | |
| tree | c1aa9ad9f973d0123747e62314fe38802ef33c33 | |
| parent | ac17c3486c6fdfbb0c3c18b99f3d8dfbff625d29 (diff) | |
| download | rust-0dec3fee34c5044f68579fedfa6882e0f69ff2cf.tar.gz rust-0dec3fee34c5044f68579fedfa6882e0f69ff2cf.zip | |
replace `try_reserve_exact` with `try_with_capacity` in `std::fs::read`
| -rw-r--r-- | library/std/src/fs.rs | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index 11f439b9996..509e673bdb8 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -285,8 +285,7 @@ pub fn read<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> { fn inner(path: &Path) -> io::Result<Vec<u8>> { let mut file = File::open(path)?; let size = file.metadata().map(|m| m.len() as usize).ok(); - let mut bytes = Vec::new(); - bytes.try_reserve_exact(size.unwrap_or(0))?; + let mut bytes = Vec::try_with_capacity(size.unwrap_or(0))?; io::default_read_to_end(&mut file, &mut bytes, size)?; Ok(bytes) } |
