pub struct Capture(/* private fields */);Expand description
The bytes that a command wrote to one of its streams
The value holds the bytes as the command wrote them. A command writes what it wants: the lines of a report, the bytes of an archive, or a sequence that is not valid UTF-8 at all. A conversion into text would lose the bytes that have no character, so the type keeps the bytes and offers the text to the caller that wants it.
§Examples
use kawauso_process::execution::Capture;
let capture = Capture::new("hello\n");
assert_eq!(capture.to_string_lossy().trim(), "hello");Implementations§
Source§impl Capture
impl Capture
Sourcepub fn new(bytes: impl Into<Vec<u8>>) -> Self
pub fn new(bytes: impl Into<Vec<u8>>) -> Self
Creates the capture of a stream from the bytes that a command wrote
§Examples
use kawauso_process::execution::Capture;
let capture = Capture::new(vec![b'h', b'i']);
assert_eq!(capture.get(), b"hi");Sourcepub fn to_string_lossy(&self) -> Cow<'_, str>
pub fn to_string_lossy(&self) -> Cow<'_, str>
Returns the capture as text
A byte that is part of no valid character becomes the replacement
character U+FFFD. The text is therefore always valid UTF-8, and a
caller that needs the bytes of the command asks for get
instead.
§Examples
use kawauso_process::execution::Capture;
let capture = Capture::new(vec![0xff]);
assert_eq!(capture.to_string_lossy(), "\u{fffd}");Trait Implementations§
Source§impl Display for Capture
Shows the capture for a reader
impl Display for Capture
Shows the capture for a reader
The text is the lossy conversion that to_string_lossy
returns, because a log line and an error message take text and not bytes.
impl Eq for Capture
Source§impl From<Vec<u8>> for Capture
Creates the capture of a stream from the bytes that a command wrote
impl From<Vec<u8>> for Capture
Creates the capture of a stream from the bytes that a command wrote