#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum StdioMode {
Inherit,
Null,
Pipe,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct StdioSpec {
stdin: StdioMode,
stdout: StdioMode,
stderr: StdioMode,
}
impl StdioSpec {
pub const fn new(stdin: StdioMode, stdout: StdioMode, stderr: StdioMode) -> Self {
Self {
stdin,
stdout,
stderr,
}
}
pub const fn captured() -> Self {
Self::new(StdioMode::Null, StdioMode::Pipe, StdioMode::Pipe)
}
pub const fn inherited() -> Self {
Self::new(StdioMode::Inherit, StdioMode::Inherit, StdioMode::Inherit)
}
pub const fn with_stdin(mut self, mode: StdioMode) -> Self {
self.stdin = mode;
self
}
pub const fn with_stdout(mut self, mode: StdioMode) -> Self {
self.stdout = mode;
self
}
pub const fn with_stderr(mut self, mode: StdioMode) -> Self {
self.stderr = mode;
self
}
pub const fn stdin(&self) -> StdioMode {
self.stdin
}
pub const fn stdout(&self) -> StdioMode {
self.stdout
}
pub const fn stderr(&self) -> StdioMode {
self.stderr
}
}
impl Default for StdioSpec {
fn default() -> Self {
Self::captured()
}
}