use std::{
error::Error,
fmt,
time::Duration,
};
use crate::error::{
CompletionError,
TerminalError,
};
#[derive(Debug)]
pub enum FinishError {
Incomplete {
elapsed: Duration,
source: CompletionError,
},
Terminal(TerminalError),
}
impl FinishError {
#[must_use]
pub const fn elapsed(&self) -> Duration {
match self {
Self::Incomplete { elapsed, .. } => *elapsed,
Self::Terminal(error) => error.elapsed(),
}
}
#[must_use]
pub const fn completion_error(&self) -> Option<&CompletionError> {
match self {
Self::Incomplete { source, .. } => Some(source),
Self::Terminal(_) => None,
}
}
}
impl fmt::Display for FinishError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Incomplete { source, .. } => source.fmt(formatter),
Self::Terminal(error) => error.fmt(formatter),
}
}
}
impl Error for FinishError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::Incomplete { source, .. } => Some(source),
Self::Terminal(error) => Some(error),
}
}
}