Skip to main content

base_scheduler/
timeout_error.rs

1// Released under the MIT License.
2// Copyright, 2026, by Samuel Williams.
3
4use crate::OperationError;
5use std::fmt;
6
7/// Failure of a clock timeout, separate from the wrapped operation's own output.
8#[derive(Debug)]
9pub enum TimeoutError {
10    /// The operation was still pending when its timer completed.
11    Elapsed,
12    /// The timer failed before the operation completed.
13    Clock(OperationError),
14}
15
16impl fmt::Display for TimeoutError {
17    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
18        match self {
19            Self::Elapsed => formatter.write_str("operation timed out"),
20            Self::Clock(error) => write!(formatter, "timeout clock failed: {error}"),
21        }
22    }
23}
24
25impl std::error::Error for TimeoutError {
26    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
27        match self {
28            Self::Elapsed => None,
29            Self::Clock(error) => Some(error),
30        }
31    }
32}