pub struct Utf8Output {
    pub status: ExitStatus,
    pub stdout: String,
    pub stderr: String,
}
Expand description

A UTF-8-decoded variant of std::process::Output (as produced by std::process::Command::output).

Construct Utf8Output from Output via the TryInto or TryFrom traits:

let output: Utf8Output = Command::new("echo")
    .arg("puppy")
    .output()
    .unwrap()
    .try_into()
    .unwrap();
assert_eq!(
    output,
    Utf8Output {
        status: ExitStatus::default(),
        stdout: String::from("puppy\n"),
        stderr: String::from(""),
    },
);

Error messages will include information about the stream that failed to decode, as well as the output (with invalid UTF-8 bytes replaced with U+FFFD REPLACEMENT CHARACTER):

let invalid = Output {
    status: ExitStatus::default(),
    stdout: Vec::from(b"\xc3\x28"), // Invalid 2-byte sequence.
    stderr: Vec::from(b""),
};

let err: Result<Utf8Output, Error> = invalid.try_into();
assert_eq!(
    err.unwrap_err().to_string(),
    "Stdout contained invalid utf-8 sequence of 1 bytes from index 0: \"�(\""
);

If there’s a lot of output (currently, more than 1024 bytes), only the portion around the decode error will be shown:

let mut stdout = vec![];
for _ in 0..300 {
    stdout.extend(b"puppy ");
}
// Add an invalid byte:
stdout[690] = 0xc0;

let invalid = Output {
    status: ExitStatus::default(),
    stdout,
    stderr: Vec::from(b""),
};

let err: Result<Utf8Output, Error> = invalid.try_into();
assert_eq!(
    err.unwrap_err().to_string(),
    "Stdout contained invalid utf-8 sequence of 1 bytes from index 690: \
    [178 bytes] \"y puppy puppy puppy puppy puppy puppy puppy puppy puppy \
    puppy puppy puppy puppy puppy puppy puppy puppy puppy puppy puppy \
    puppy puppy puppy puppy puppy puppy puppy puppy puppy puppy puppy \
    puppy puppy puppy puppy puppy puppy puppy puppy puppy puppy puppy \
    puppy puppy puppy puppy puppy puppy puppy puppy puppy puppy puppy \
    puppy puppy puppy puppy puppy puppy puppy puppy puppy puppy puppy \
    puppy puppy puppy puppy puppy puppy puppy puppy puppy puppy puppy \
    puppy puppy puppy puppy puppy puppy puppy puppy puppy puppy �uppy \
    puppy puppy puppy puppy puppy puppy puppy puppy puppy puppy puppy \
    puppy puppy puppy puppy puppy puppy puppy puppy puppy puppy puppy \
    puppy puppy puppy puppy puppy puppy puppy puppy puppy puppy puppy \
    puppy puppy puppy puppy puppy puppy puppy puppy puppy puppy puppy \
    puppy puppy puppy puppy puppy puppy puppy puppy puppy puppy puppy \
    puppy puppy puppy puppy puppy puppy puppy puppy puppy puppy puppy \
    puppy puppy puppy puppy puppy puppy puppy puppy puppy puppy puppy \
    puppy puppy puppy puppy puppy puppy puppy pu\" [598 bytes]"
);

Fields§

§status: ExitStatus

The std::process::Command’s exit status.

§stdout: String

The contents of the std::process::Command’s stdout stream, decoded as UTF-8.

§stderr: String

The contents of the std::process::Command’s stderr stream, decoded as UTF-8.

Trait Implementations§

source§

impl Clone for Utf8Output

source§

fn clone(&self) -> Utf8Output

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Utf8Output

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq for Utf8Output

source§

fn eq(&self, other: &Utf8Output) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl TryFrom<&Output> for Utf8Output

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(_: &Output) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Output> for Utf8Output

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(_: Output) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Eq for Utf8Output

source§

impl StructuralPartialEq for Utf8Output

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.