async_time_mock_async_std/
timeout_error.rs

1use std::error::Error;
2use std::fmt::{Debug, Display, Formatter};
3
4// NOTE That the can't implement PartialEq, Eq, Clone or Copy, because TimeHandlerGuard doesn't support that.
5#[must_use = "TimeoutError must only be dropped once all side-effects of the timeout have been handled."]
6#[derive(Debug)]
7pub enum TimeoutError {
8	Real(async_std::future::TimeoutError),
9	#[cfg(feature = "mock")]
10	Mock(async_time_mock_core::Elapsed),
11}
12
13impl Display for TimeoutError {
14	fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
15		use TimeoutError::*;
16		match self {
17			Real(error) => Display::fmt(error, formatter),
18			#[cfg(feature = "mock")]
19			Mock(elapsed) => Display::fmt(elapsed, formatter),
20		}
21	}
22}
23
24impl Error for TimeoutError {}
25
26impl From<async_std::future::TimeoutError> for TimeoutError {
27	fn from(error: async_std::future::TimeoutError) -> Self {
28		Self::Real(error)
29	}
30}
31
32#[cfg(feature = "mock")]
33impl From<async_time_mock_core::Elapsed> for TimeoutError {
34	fn from(elapsed: async_time_mock_core::Elapsed) -> Self {
35		Self::Mock(elapsed)
36	}
37}