Collect all of the output written to stdout and stderr into a simple human-readable string, to be written to out_buf from run_wasi on success. Lossy utf8 conversion because this is an example.
(&self)
| 183 | // human-readable string, to be written to out_buf from run_wasi on |
| 184 | // success. Lossy utf8 conversion because this is an example. |
| 185 | fn output(&self) -> Result<String> { |
| 186 | let mut out = String::new(); |
| 187 | let stdout = self.stdout.log.borrow(); |
| 188 | if !stdout.is_empty() { |
| 189 | write!(&mut out, "stdout:\n")?; |
| 190 | for chunk in stdout.iter() { |
| 191 | write!(&mut out, "{}", String::from_utf8_lossy(chunk))?; |
| 192 | } |
| 193 | } |
| 194 | let stderr = self.stderr.log.borrow(); |
| 195 | if !stderr.is_empty() { |
| 196 | write!(&mut out, "stderr:\n")?; |
| 197 | for chunk in stderr.iter() { |
| 198 | write!(&mut out, "{}", String::from_utf8_lossy(chunk))?; |
| 199 | } |
| 200 | } |
| 201 | Ok(out) |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | // Add the minimum number of wasi interfaces to the Linker to instantiate the |