summaryrefslogtreecommitdiff
path: root/src/client/executor.rs
blob: 35e3f752e657bb4209c8b46d8719df72856d28f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use remote_control_rs::tasks::{IntoTaskErr, Task};

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

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