summaryrefslogtreecommitdiff
path: root/src/client/executor.rs
blob: 1e6968cc0e1af9495eff92f6b778bf00dd7d68a0 (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
27
use remote_control_rs::tasks::{IntoTaskErr, Task};

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

impl<'a, 't> Executor<'a, 't> {
    pub fn new(task: &'t Task, args: impl IntoIterator<Item = &'a str>) -> Result<Self, IntoTaskErr> {
        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()
    }
}