mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-06-14 14:46:37 +00:00
Fix compilation
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
6770f34ec4
commit
a30d61e5c4
1 changed files with 19 additions and 15 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue