Skip to main content

ProcessEvent

Enum ProcessEvent 

Source
pub enum ProcessEvent {
    Started {
        id: RunId,
        invocation: Invocation,
        process_id: Option<ProcessId>,
    },
    Line {
        id: RunId,
        line: Line,
    },
    Finished {
        id: RunId,
        invocation: Invocation,
        outcome: Outcome,
        duration: Duration,
    },
}
Expand description

One step in the run of an external program

Clawless sends these events while a program runs, so that a presenter can render the output of the program as it arrives instead of after the program ends. A build that takes two minutes therefore shows two minutes of progress.

Every run sends Started first and Finished last, with one Line in between for each line that the program wrote. Two things end a run without a Finished: a consumer that stopped listening, which cannot be told anything, and a caller that dropped the run instead of cancelling it, which leaves no code to send the event.

Each variant carries the RunId of its run. Two programs that run at the same time interleave their lines in the channel, and the identity is what separates them again. Started and Finished also carry the command itself, so that a presenter which keeps no state can name the program it is reporting on.

Started carries the ProcessId of the program as well. That value is the name the operating system knows the program by, which is what an operator needs to find it in a process list.

§Examples

use clawless_core::event::process::{ProcessEvent, RunId};
use clawless_core::process::Invocation;

let event = ProcessEvent::Started {
    id: RunId::next(),
    invocation: Invocation::new("git").arg("status"),
    process_id: None,
};

assert_eq!(event.to_string(), "$ git status");

Variants§

§

Started

The program started

The event names the command, which is what a consumer shows while the program runs.

Fields

§id: RunId

The run that started

§invocation: Invocation

The command that the run starts

§process_id: Option<ProcessId>

The identifier that the operating system gave the program

None when the operating system did not report one. A consumer that names the program to a tool of the platform, or that writes the identifier to a log, reads it here.

§

Line

The program wrote one line

The line carries the stream that produced it, so that a consumer can show a diagnostic apart from a result, or drop one of the two. It holds no characters that end a line.

Fields

§id: RunId

The run that wrote the line

§line: Line

The line that the program wrote

§

Finished

The program ended

No further event carries this identity. A consumer that shows running programs removes the run here.

Fields

§id: RunId

The run that ended

§invocation: Invocation

The command that ran

§outcome: Outcome

The way in which the run ended

§duration: Duration

The time from the start of the program to the end of the run

Implementations§

Source§

impl ProcessEvent

Source

pub fn id(&self) -> RunId

Returns the run that the event belongs to

A consumer that groups the events of one program reads the identity here instead of matching on the variant.

§Examples
use clawless_core::event::process::{ProcessEvent, RunId};
use clawless_core::process::Invocation;

let id = RunId::next();
let event = ProcessEvent::Started {
    id,
    invocation: Invocation::new("git"),
    process_id: None,
};

assert_eq!(event.id(), id);

Trait Implementations§

Source§

impl Clone for ProcessEvent

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ProcessEvent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for ProcessEvent

Renders the event as one line of a transcript

The start of a run reads as a shell prompt, a line of output reads as the program wrote it, and the end of a run states what became of the command. A consumer that wants another shape matches on the variant and builds its own.

The text never names the stream that produced a line. A presenter that separates the two writes them to different places instead of labelling them, which keeps the output of the program readable.

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for ProcessEvent

Source§

impl PartialEq for ProcessEvent

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ProcessEvent

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.