Crate utf8_command

source ·
Expand description

Provides the Utf8Output type, 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"puppy doggy \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 12: \"puppy doggy �(\""
);

Structs§

Enums§