qubit_progress/error/
terminal_error.rs1use std::error::Error;
12use std::fmt;
13use std::time::Duration;
14
15use crate::error::EmissionError;
16
17#[derive(Clone, Debug)]
19pub struct TerminalError {
20 elapsed: Duration,
21 source: EmissionError,
22}
23
24impl TerminalError {
25 pub(crate) const fn new(elapsed: Duration, source: EmissionError) -> Self {
27 Self { elapsed, source }
28 }
29
30 #[must_use]
32 pub const fn elapsed(&self) -> Duration {
33 self.elapsed
34 }
35
36 #[must_use]
38 pub const fn emission_error(&self) -> &EmissionError {
39 &self.source
40 }
41
42 #[must_use]
44 pub fn into_emission_error(self) -> EmissionError {
45 self.source
46 }
47
48 #[must_use]
50 pub fn into_parts(self) -> (Duration, EmissionError) {
51 (self.elapsed, self.source)
52 }
53}
54
55impl fmt::Display for TerminalError {
56 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
58 write!(
59 formatter,
60 "terminal progress report failed after {:?}: {}",
61 self.elapsed, self.source
62 )
63 }
64}
65
66impl Error for TerminalError {
67 fn source(&self) -> Option<&(dyn Error + 'static)> {
69 Some(&self.source)
70 }
71}