Fix compilation

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2024-11-14 00:17:37 +11:00 committed by Jiahao XU
parent 6770f34ec4
commit a30d61e5c4

View file

@ -4,7 +4,7 @@ use std::{
str,
};
use tokio::process::Command;
use tokio::{io::AsyncWriteExt, process::Command};
use zeroize::Zeroizing;
pub(super) async fn get() -> io::Result<Zeroizing<Box<str>>> {
@ -56,18 +56,22 @@ pub(super) async fn get() -> io::Result<Zeroizing<Box<str>>> {
Ok(Zeroizing::new(password.into()))
}
// Helper function to execute a command with input
async fn output_async_with_stdin(
cmd: &mut Command,
input: &[u8],
) -> io::Result<Output> {
let mut child = cmd.spawn()?;
let mut stdin = child.stdin.take().expect("Failed to open stdin");
tokio::spawn(async move {
use tokio::io::AsyncWriteExt;
let _ = stdin.write_all(input).await;
});
child.wait_with_output().await
trait CommandExt {
// Helper function to execute a command with input
async fn output_async_with_stdin(&mut self, input: &[u8]) -> io::Result<Output>;
}
impl CommandExt for Command {
async fn output_async_with_stdin(&mut self, input: &[u8]) -> io::Result<Output> {
let mut child = self.spawn()?;
child
.stdin
.take()
.expect("Failed to open stdin")
.write_all(input)
.await?;
child.wait_with_output().await
}
}