Hello,
I have (I believe) successfully written some code to write to stdin of a spawned command - I lifted the code from StackOverflow. Here is the snippet from my repository:
let command_stdin = match command.stdin.as_mut() {
Some(command_stdin) => command_stdin,
None => {
eprintln!("Unable to get mutable reference to stdin.");
process::exit(63);
},
};
match command_stdin
.write_all(
clear_text.as_bytes()
)
{
Ok(_) => (),
Err(err) => {
eprintln!("Unable to write bytes to stdin of encryption process: '{err}'");
process::exit(64);
},
};
// Close stdin to finish and avoid indefinite blocking
drop(command_stdin);
Until today I have never run clippy. Now that I've run clippy against my software I get the following error:
Checking puppet-retrieve-ssh-keys v0.2.3 (/home/mzagrabe/git/internal/puppet-retrieve-ssh-keys)
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing
--> src/puppet_retrieve_ssh_keys/writer.rs:153:9
|
153 | drop(command_stdin);
| ^^^^^^^^^^^^^^^^^^^
|
note: argument has type `&mut std::process::ChildStdin`
--> src/puppet_retrieve_ssh_keys/writer.rs:153:14
|
153 | drop(command_stdin);
| ^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#drop_ref
= note: `#[deny(clippy::drop_ref)]` on by default
error: could not compile `puppet-retrieve-ssh-keys` due to previous error
To which I've fixed the clippy error by replacing the top line in my code with:
let mut command_stdin = match command.stdin.take() {
I have a few questions...
-
I'm having a hard time finding documentation on the ".take()" function/method. Could anyone point me in the right direction to find the docs for it?
-
Do I need the "drop()" on the command_stdin? I copied the initial code from StackOverflow and I'm not certain of its correctness.
-
If folks have any feedback on my code for writing to the stdin of a spawned command please let me know.
Thanks for the help!
-m