1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2024-12-11 13:18:43 +02:00

Don't allocate in success case (#506)

`format!` was being called (and allocating a string) even in the success case.
This commit is contained in:
Andrew Walbran 2023-03-15 08:06:35 +00:00 committed by GitHub
parent 9ee562c267
commit 7a22d5567a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,7 +12,7 @@ use anyhow::{Context, Result, bail};
fn read_username(path: &str) -> Result<String> {
let mut username = String::with_capacity(100);
fs::File::open(path)
.context(format!("Failed to open {path}"))?
.with_context(|| format!("Failed to open {path}"))?
.read_to_string(&mut username)
.context("Failed to read")?;
if username.is_empty() {