izzilis/src/model.rs

37 lines
929 B
Rust

use std::{io, process::Command};
pub trait SampleModel {
fn get_sample(&self) -> Result<String, io::Error>;
}
pub struct GPTSampleModel {
python_command: String,
command_working_path: String,
command_args: Vec<String>,
}
impl SampleModel for GPTSampleModel {
fn get_sample(&self) -> Result<String, io::Error> {
let cmd_output = Command::new(&self.python_command)
.current_dir(&self.command_working_path)
.args(&self.command_args)
.output()?;
Ok(String::from_utf8_lossy(&cmd_output.stdout).to_string())
}
}
impl GPTSampleModel {
pub fn new(
python_command: String,
command_working_path: String,
command_args: Vec<String>,
) -> GPTSampleModel {
Self {
python_command: python_command,
command_working_path: command_working_path,
command_args: command_args,
}
}
}