tokio's arg() returns a mutable reference to a Command. How can I assign it to a field?
pub struct Manager<'a> {
pub cmd: &'a mut tokio::process::Command
}
impl<'a> Manager<'a> {
pub fn new() -> Manager<'a> {
Manager {
cmd: tokio::process::Command::new("ls").arg("la")
}
}
}
Error Message:
returns a value referencing data owned by the current function
The method returns a reference to the same
Commandit was invoked on, just to make it easy to chain method calls (command.arg("abc").arg("def").spawn()). You may as well ignore its return value and just assign theCommandto the field: