MCPcopy Create free account
hub / github.com/elastio/devx / stdout_lines

Method stdout_lines

devx-cmd/src/lib.rs:646–659  ·  view source on GitHub ↗

Returns an iterator over the lines of data output to `stdout` by the child process. Beware that the iterator buffers the output, thus when the it is dropped the buffered data will be discarded and following reads won't restore it. The returned line of output is logged via [`log`] crate according to [`Cmd::log_cmd()`] configuration. # Panics Panics if some [`std::io::Error`] happens during the rea

(&mut self)

Source from the content-addressed store, hash-verified

644 /// Panics if some [`std::io::Error`] happens during the reading.
645 /// All invariants from [`Child::read_bytes()`] apply here too.
646 pub fn stdout_lines(&mut self) -> impl Iterator<Item = String> + '_ {
647 let log_cmd = self.cmd.0.log_cmd;
648 let id = self.child.id();
649 let bin_name = self.cmd.bin_name();
650 let stdout = io::BufReader::new(self.child.stdout.as_mut().unwrap());
651 stdout
652 .lines()
653 .map(|line| line.expect("Unexpected io error"))
654 .inspect(move |line| {
655 if let Some(level) = log_cmd {
656 log::log!(level, "[{} {}] {}", id, bin_name, line);
657 }
658 })
659 }
660}
661
662/// Defines the kind of standard process output stream.

Callers

nothing calls this directly

Calls 2

bin_nameMethod · 0.80
as_mutMethod · 0.80

Tested by

no test coverage detected