use std::time::Duration;
mod process;
mod request;
use request::{CapturedOutput, RunnerRequest};
pub trait Runner: Send + Sync {
fn run(
&self,
program: &str,
args: &[&str],
remove: &[&str],
timeout: Duration,
) -> Result<String, String>;
}
pub struct SystemRunner;
impl Runner for SystemRunner {
fn run(
&self,
program: &str,
args: &[&str],
remove: &[&str],
timeout: Duration,
) -> Result<String, String> {
let output = process::capture(RunnerRequest::new(program, args, remove, timeout))?;
successful_output(program, output)
}
}
fn successful_output(program: &str, output: CapturedOutput) -> Result<String, String> {
match output.exit_code {
Some(0) => Ok(output.stdout),
_ => Err(format!("{program} failed")),
}
}
#[cfg(test)]
mod tests;