Closed
Description
Version
Using tokio 1.24.2, rust 1.67
Platform
Windows 10, 64 bit
Description
The example of tokio::process::Command::arg
(and other methods of Command
) suggests the following code:
use tokio::process::Command;
let command = Command::new("ls").arg("-l").arg("-a");
which naturally extends to
#[tokio::test]
async fn wontcompile() {
use tokio::process::Command;
let command = Command::new("ls").arg("-l").arg("-a");
command.output();
}
This snippet won't compile, however, with the error:
error[E0716]: temporary value dropped while borrowed
--> taumada-rusty-runner\src\lib.rs:80:19
|
80 | let command = Command::new("ls").arg("-l").arg("-a");
| ^^^^^^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
| |
| creates a temporary value which is freed while still in use
81 | command.output();
| ---------------- borrow later used here
|
= note: consider using a `let` binding to create a longer lived value
For more information about this error, try `rustc --explain E0716`.
Resolution
I suggest to either, like std::process::Command::arg
, add a .spawn().unwrap()
, or the remove the let binding named command
.