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:
parent
9ee562c267
commit
7a22d5567a
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user