Skip to main content

LineStreamHandler

Struct LineStreamHandler 

Source
pub struct LineStreamHandler { /* private fields */ }
Expand description

Streaming per-line output handler: prints each completed output line as soon as it arrives instead of buffering everything until command exit.

Ports the upstream line-buffering fix (ClusterShell commits 65e5433 / GH#528/GH#597): in Python, Display reconfigures sys.stdout / sys.stderr with line_buffering=True so that piped consumers observe lines in real time. Rust’s io::Stdout is already a LineWriter, and this handler additionally flushes after every completed line, giving the same observable behavior: lines arrive as they are produced, not in one block at process exit.

Partial lines are buffered per node and flushed on on_close, so no output is lost even when a node’s final line lacks a trailing newline. Lines print to stdout with the usual node: label unless disabled.

Note: the core ExecWorker currently reports raw pipe fds in on_read (never normalized to 1/2), so stderr chunks cannot be told apart from stdout here — consistent with TaskGatheringHandler, which also folds them into the stdout buffers. Once the core normalizes fds, a fd == 2 branch can route stderr lines to stderr like Python’s print_line_error.

An optional inner handler (e.g. ProgressHandler) is chained after every callback.

Implementations§

Source§

impl LineStreamHandler

Source

pub fn new(label: bool) -> Self

Create a handler; label controls the node: prefix on lines.

Source

pub fn with_inner(self, inner: Box<dyn EventHandler>) -> Self

Chain another handler (called after this one on every event).

Trait Implementations§

Source§

impl EventHandler for LineStreamHandler

Source§

fn on_start(&mut self, worker: &dyn Worker)

Called when the worker starts.
Source§

fn on_read(&mut self, node: &str, fd: RawFd, msg: &[u8])

Called when data is available for reading from a node.
Source§

fn on_close(&mut self, node: &str, rc: i32)

Called when a connection to a node is closed.
Source§

fn on_timeout(&mut self, node: &str)

Called when a node operation times out.
Source§

fn on_error(&mut self, node: &str, error: &WorkerError)

Called when an error occurs for a node.
Source§

fn take_buffers( &mut self, ) -> (HashMap<String, Vec<Vec<u8>>>, HashMap<String, Vec<Vec<u8>>>, HashSet<String>)

Extract buffered stdout/stderr data from this handler. Returns (stdout, stderr, timeouts) where stdout/stderr are node -> Vec<chunks>. Default returns empty maps. Used by Task to collect results after execution.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V