use std::error::Error;
use std::fmt;
use std::time::Duration;
use crate::error::EmissionError;
#[derive(Clone, Debug)]
pub struct TerminalError {
elapsed: Duration,
source: EmissionError,
}
impl TerminalError {
pub(crate) const fn new(elapsed: Duration, source: EmissionError) -> Self {
Self { elapsed, source }
}
#[must_use]
pub const fn elapsed(&self) -> Duration {
self.elapsed
}
#[must_use]
pub const fn emission_error(&self) -> &EmissionError {
&self.source
}
#[must_use]
pub fn into_emission_error(self) -> EmissionError {
self.source
}
#[must_use]
pub fn into_parts(self) -> (Duration, EmissionError) {
(self.elapsed, self.source)
}
}
impl fmt::Display for TerminalError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
formatter,
"terminal progress report failed after {:?}: {}",
self.elapsed, self.source
)
}
}
impl Error for TerminalError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
Some(&self.source)
}
}