Skip to content

Commit f024019

Browse files
committed
Avoid unnecessary clones and string allocations in build script
1 parent cae7ead commit f024019

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

godot-bindings/src/godot_exe.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub(crate) fn read_godot_version(godot_bin: &Path) -> GodotVersion {
104104
cmd.arg("--version");
105105

106106
let output = execute(cmd, "read Godot version");
107-
let stdout = String::from_utf8(output.stdout).expect("convert Godot version to UTF-8");
107+
let stdout = std::str::from_utf8(&output.stdout).expect("convert Godot version to UTF-8");
108108

109109
match parse_godot_version(&stdout) {
110110
Ok(parsed) => {
@@ -277,21 +277,13 @@ fn try_execute(mut cmd: Command, error_message: &str) -> Result<Output, String>
277277
.output()
278278
.map_err(|_| format!("failed to invoke command ({error_message})\n\t{cmd:?}"))?;
279279

280+
println!("[stdout] {}", std::str::from_utf8(&output.stdout).unwrap());
281+
println!("[stderr] {}", std::str::from_utf8(&output.stderr).unwrap());
282+
println!("[status] {}", output.status);
283+
280284
if output.status.success() {
281-
println!(
282-
"[stdout] {}",
283-
String::from_utf8(output.stdout.clone()).unwrap()
284-
);
285-
println!(
286-
"[stderr] {}",
287-
String::from_utf8(output.stderr.clone()).unwrap()
288-
);
289-
println!("[status] {}", output.status);
290285
Ok(output)
291286
} else {
292-
println!("[stdout] {}", String::from_utf8(output.stdout).unwrap());
293-
println!("[stderr] {}", String::from_utf8(output.stderr).unwrap());
294-
println!("[status] {}", output.status);
295287
Err(format!(
296288
"command returned error ({error_message})\n\t{cmd:?}"
297289
))

0 commit comments

Comments
 (0)