mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-04-26 09:12:58 +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> {
|
fn read_username(path: &str) -> Result<String> {
|
||||||
let mut username = String::with_capacity(100);
|
let mut username = String::with_capacity(100);
|
||||||
fs::File::open(path)
|
fs::File::open(path)
|
||||||
.context(format!("Failed to open {path}"))?
|
.with_context(|| format!("Failed to open {path}"))?
|
||||||
.read_to_string(&mut username)
|
.read_to_string(&mut username)
|
||||||
.context("Failed to read")?;
|
.context("Failed to read")?;
|
||||||
if username.is_empty() {
|
if username.is_empty() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user