memfd_exec/
output.rs

1use std::fmt::{Debug, Formatter, Result};
2use std::str::from_utf8;
3
4use crate::process::ExitStatus;
5
6/// The output of a child process, including the exit status and output streams.
7#[derive(PartialEq, Clone, Eq)]
8pub struct Output {
9    /// The exit status of the child process
10    pub status: ExitStatus,
11    /// The data that the child process wrote to stdout
12    pub stdout: Vec<u8>,
13    /// The data that the child process wrote to stderr
14    pub stderr: Vec<u8>,
15}
16
17impl Debug for Output {
18    fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
19        let stdout_utf8 = from_utf8(&self.stdout);
20        let stdout_debug: &dyn Debug = match stdout_utf8 {
21            Ok(ref str) => str,
22            Err(_) => &self.stdout,
23        };
24
25        let stderr_utf8 = from_utf8(&self.stderr);
26        let stderr_debug: &dyn Debug = match stderr_utf8 {
27            Ok(ref str) => str,
28            Err(_) => &self.stderr,
29        };
30
31        fmt.debug_struct("Output")
32            .field("status", &self.status)
33            .field("stdout", stdout_debug)
34            .field("stderr", stderr_debug)
35            .finish()
36    }
37}