cageforge_command/
stdio.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub enum StdioMode {
11 Inherit,
14 Null,
16 Pipe,
18}
19
20#[derive(Debug, Clone, Copy, PartialEq, Eq)]
22pub struct StdioSpec {
23 stdin: StdioMode,
24 stdout: StdioMode,
25 stderr: StdioMode,
26}
27
28impl StdioSpec {
29 pub const fn new(stdin: StdioMode, stdout: StdioMode, stderr: StdioMode) -> Self {
31 Self {
32 stdin,
33 stdout,
34 stderr,
35 }
36 }
37
38 pub const fn captured() -> Self {
40 Self::new(StdioMode::Null, StdioMode::Pipe, StdioMode::Pipe)
41 }
42
43 pub const fn inherited() -> Self {
45 Self::new(StdioMode::Inherit, StdioMode::Inherit, StdioMode::Inherit)
46 }
47
48 pub const fn with_stdin(mut self, mode: StdioMode) -> Self {
50 self.stdin = mode;
51 self
52 }
53
54 pub const fn with_stdout(mut self, mode: StdioMode) -> Self {
56 self.stdout = mode;
57 self
58 }
59
60 pub const fn with_stderr(mut self, mode: StdioMode) -> Self {
62 self.stderr = mode;
63 self
64 }
65
66 pub const fn stdin(&self) -> StdioMode {
68 self.stdin
69 }
70
71 pub const fn stdout(&self) -> StdioMode {
73 self.stdout
74 }
75
76 pub const fn stderr(&self) -> StdioMode {
78 self.stderr
79 }
80}
81
82impl Default for StdioSpec {
83 fn default() -> Self {
84 Self::captured()
85 }
86}