Skip to content

Commit e8dd729

Browse files
committed
Avoid an additional allocation when logging errors
The call to `to_string()` results in an unnecessary allocation. `Error` only implements `ToString` through the `Display` trait. The same formatting logic is used, but calling `to_string()` causes an additional heap allocation.
1 parent 36c8a15 commit e8dd729

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/middleware/log_request.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl Handler for LogRequests {
4343
};
4444

4545
let error = if let Err(ref e) = res {
46-
format!(" error=\"{}\"", e.to_string())
46+
format!(" error=\"{}\"", e)
4747
} else {
4848
String::new()
4949
};

0 commit comments

Comments
 (0)