use std::fmt::{self, Display};
use std::process::ExitStatus;
#[derive(Clone, Eq, PartialEq, Debug)]
pub enum Outcome {
Cancelled,
Exited(ExitStatus),
Incomplete,
}
impl Display for Outcome {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Cancelled => formatter.write_str("was cancelled before it ended"),
Self::Exited(status) => match status.code() {
Some(code) => write!(formatter, "exited with code {code}"),
None => formatter.write_str("ended without an exit code"),
},
Self::Incomplete => formatter.write_str("ended without a result"),
}
}
}
#[cfg(test)]
mod tests {
#![allow(clippy::missing_panics_doc)]
use super::*;
#[test]
fn display_with_cancelled_names_the_cancellation() {
let outcome = Outcome::Cancelled;
let text = outcome.to_string();
assert_eq!(text, "was cancelled before it ended");
}
#[test]
fn display_with_incomplete_names_the_missing_result() {
let outcome = Outcome::Incomplete;
let text = outcome.to_string();
assert_eq!(text, "ended without a result");
}
#[test]
fn trait_send() {
fn assert_send<T: Send>() {}
assert_send::<Outcome>();
}
#[test]
fn trait_sync() {
fn assert_sync<T: Sync>() {}
assert_sync::<Outcome>();
}
#[test]
fn trait_unpin() {
fn assert_unpin<T: Unpin>() {}
assert_unpin::<Outcome>();
}
}