summaryrefslogtreecommitdiff
path: root/src/client/executor.rs
blob: ad419f0db9f8d7075ceb2b8fd1e9b5068b9c3bfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use remote_control_rs::tasks::{IntoTask, IntoTaskErr, Task};

pub struct Executor {
    task: &'static Task,
    args: Box<[String]>,
    output: Option<Result<String, String>>,
}

impl Executor {
    pub fn new(
        task: impl IntoTask,
        args: impl IntoIterator<Item = String>,
    ) -> Result<Self, IntoTaskErr> {
        let task = task.into_task()?;
        Ok(Self {
            task: task,
            args: args.into_iter().collect(),
            output: None,
        })
    }

    pub fn run(&mut self) -> Option<&Result<String, String>> {
        self.output = Some((self.task.exec)(&self.args));
        self.output.as_ref()
    }
}