1#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5#[non_exhaustive]
6pub enum StreamType {
7 Stdout,
9 Stderr,
11}
12
13impl StreamType {
14 #[must_use]
16 pub fn as_str(self) -> &'static str {
17 match self {
18 Self::Stdout => "stdout",
19 Self::Stderr => "stderr",
20 }
21 }
22}
23
24#[derive(Debug, Clone, PartialEq, Eq)]
26#[non_exhaustive]
27pub struct StreamChunk {
28 pub data: String,
30 pub stream_type: StreamType,
32}
33
34impl StreamChunk {
35 pub fn new(data: impl Into<String>, stream_type: StreamType) -> Self {
37 Self {
38 data: data.into(),
39 stream_type,
40 }
41 }
42}
43
44#[derive(Debug, Clone, PartialEq, Eq)]
48#[non_exhaustive]
49pub struct FileInfo {
50 pub name: String,
52 pub is_dir: Option<bool>,
54 pub size: Option<u64>,
56}
57
58impl FileInfo {
59 pub fn new(name: impl Into<String>) -> Self {
61 Self {
62 name: name.into(),
63 is_dir: None,
64 size: None,
65 }
66 }
67
68 #[must_use]
70 pub fn with_is_dir(mut self, is_dir: bool) -> Self {
71 self.is_dir = Some(is_dir);
72 self
73 }
74
75 #[must_use]
77 pub fn with_size(mut self, size: u64) -> Self {
78 self.size = Some(size);
79 self
80 }
81}
82
83#[derive(Debug, Clone, PartialEq, Eq)]
87#[non_exhaustive]
88pub struct OutputFile {
89 pub name: String,
91 pub content: Vec<u8>,
93 pub mime_type: String,
95}
96
97impl OutputFile {
98 pub fn new(name: impl Into<String>, content: impl Into<Vec<u8>>, mime_type: impl Into<String>) -> Self {
100 Self {
101 name: name.into(),
102 content: content.into(),
103 mime_type: mime_type.into(),
104 }
105 }
106}
107
108#[derive(Debug, Clone, PartialEq, Eq)]
110#[non_exhaustive]
111pub struct ExecutionResult {
112 pub exit_code: i32,
115 pub stdout: String,
117 pub stderr: String,
119 pub output_files: Vec<OutputFile>,
121}
122
123impl ExecutionResult {
124 pub fn new(exit_code: i32, stdout: impl Into<String>, stderr: impl Into<String>) -> Self {
126 Self {
127 exit_code,
128 stdout: stdout.into(),
129 stderr: stderr.into(),
130 output_files: Vec::new(),
131 }
132 }
133
134 #[must_use]
136 pub fn with_output_files(mut self, output_files: Vec<OutputFile>) -> Self {
137 self.output_files = output_files;
138 self
139 }
140}
141
142#[derive(Debug, Clone, PartialEq, Eq)]
147#[non_exhaustive]
148pub enum ExecutionStreamItem {
149 StreamChunk(StreamChunk),
151 ExecutionResult(ExecutionResult),
153}
154
155impl From<StreamChunk> for ExecutionStreamItem {
156 fn from(chunk: StreamChunk) -> Self {
157 Self::StreamChunk(chunk)
158 }
159}
160
161impl From<ExecutionResult> for ExecutionStreamItem {
162 fn from(result: ExecutionResult) -> Self {
163 Self::ExecutionResult(result)
164 }
165}