Skip to main content

beez_process/
process_call.rs

1use std::ffi::OsString;
2use std::path::PathBuf;
3
4/// A direct host-process invocation.
5#[derive(Clone, Debug, Eq, PartialEq)]
6pub struct ProcessCall {
7    program: PathBuf,
8    arguments: Vec<OsString>,
9}
10
11impl ProcessCall {
12    /// Builds a process request.
13    #[must_use]
14    pub fn new(program: impl Into<PathBuf>) -> Self {
15        Self {
16            program: program.into(),
17            arguments: Vec::new(),
18        }
19    }
20
21    /// Adds a literal process argument.
22    #[must_use]
23    pub fn argument(mut self, argument: impl Into<OsString>) -> Self {
24        self.arguments.push(argument.into());
25        self
26    }
27
28    /// Adds literal process arguments, in the order they are given.
29    #[must_use]
30    pub fn arguments(mut self, arguments: impl IntoIterator<Item = impl Into<OsString>>) -> Self {
31        self.arguments.extend(arguments.into_iter().map(Into::into));
32        self
33    }
34
35    pub(crate) fn into_parts(self) -> (PathBuf, Vec<OsString>) {
36        (self.program, self.arguments)
37    }
38}