Struct utf8_command::Utf8Output
source · 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
impl Clone for Utf8Output
source§fn clone(&self) -> Utf8Output
fn clone(&self) -> Utf8Output
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for Utf8Output
impl Debug for Utf8Output
source§impl PartialEq for Utf8Output
impl PartialEq for Utf8Output
source§fn eq(&self, other: &Utf8Output) -> bool
fn eq(&self, other: &Utf8Output) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl TryFrom<&Output> for Utf8Output
impl TryFrom<&Output> for Utf8Output
source§impl TryFrom<Output> for Utf8Output
impl TryFrom<Output> for Utf8Output
impl Eq for Utf8Output
impl StructuralPartialEq for Utf8Output
Auto Trait Implementations§
impl Freeze for Utf8Output
impl RefUnwindSafe for Utf8Output
impl Send for Utf8Output
impl Sync for Utf8Output
impl Unpin for Utf8Output
impl UnwindSafe for Utf8Output
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more