You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ripgrep-all/src/adapters/spawning.rs

29 lines
754 B
Rust

use super::*;
use std::io::Write;
use std::process::Command;
use std::process::Stdio;
pub trait SpawningFileAdapter: GetMetadata {
fn command(&self, inp_fname: &str) -> Command;
}
impl<T> FileAdapter for T
where
T: SpawningFileAdapter,
{
fn adapt(&self, inp_fname: &str, oup: &mut dyn Write) -> std::io::Result<()> {
let mut cmd = self.command(inp_fname).stdout(Stdio::piped()).spawn()?;
let stdo = cmd.stdout.as_mut().expect("is piped");
std::io::copy(stdo, oup)?;
let status = cmd.wait()?;
if status.success() {
Ok(())
} else {
Err(std::io::Error::new(
std::io::ErrorKind::Other,
"subprocess failed",
))
}
}
}