use std::fmt;
use std::io;
use std::time::Duration;
use super::Captured;
use crate::{Outcome, Status};
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ChildFinished {
pub(super) outcome: Outcome,
pub(super) status: Option<Status>,
pub(super) stdout: Captured,
pub(super) stderr: Captured,
pub(super) first_stdout: Option<Duration>,
pub(super) survivors: bool,
pub(super) overdue: bool,
}
impl ChildFinished {
#[must_use]
pub const fn outcome(&self) -> Outcome {
self.outcome
}
#[must_use]
pub const fn status(&self) -> Option<Status> {
self.status
}
#[must_use]
pub const fn survivors(&self) -> bool {
self.survivors
}
#[must_use]
pub const fn was_overdue(&self) -> bool {
self.overdue
}
#[must_use]
pub const fn stdout(&self) -> &Captured {
&self.stdout
}
#[must_use]
pub const fn stderr(&self) -> &Captured {
&self.stderr
}
#[must_use]
pub fn into_output(self) -> (Captured, Captured) {
(self.stdout, self.stderr)
}
#[must_use]
pub const fn first_stdout(&self) -> Option<Duration> {
self.first_stdout
}
}
#[derive(Debug)]
#[non_exhaustive]
pub enum RunError {
Start(io::Error),
Run(io::Error),
}
impl fmt::Display for RunError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::Start(_) => "cannot start the program",
Self::Run(_) => "cannot follow the program to its end",
})
}
}
impl std::error::Error for RunError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Start(error) | Self::Run(error) => Some(error),
}
}
}