devela/phys/time/
error.rs
1use crate::impl_error;
7#[cfg(feature = "std")]
8use crate::Duration;
9
10#[cfg(feature = "std")]
11use ::std::time::SystemTimeError as StdSystemTimeError;
12
13impl_error! { individual:
14 #[cfg(feature = "std")]
15 #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "std")))]
16 pub struct SystemTimeError(Duration);
17 DOC_SYSTEM_TIME_ERROR =
18 "Returned from the `duration_since` and `elapsed` methods on `SystemTime`.\n\n
19This is basically a replication of `std::time::`[`SystemTimeError`][StdSystemTimeError].",
20 self+f => write!(f, "SystemTimeError difference: {:?}", self.0)
21}
22#[cfg(feature = "std")]
23#[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "std")))]
24impl From<StdSystemTimeError> for SystemTimeError {
25 fn from(from: StdSystemTimeError) -> Self {
26 SystemTimeError(from.duration())
27 }
28}
29
30#[cfg(all(feature = "error", feature = "time"))]
31pub use full_composite::*;
32#[cfg(all(feature = "error", feature = "time"))]
33#[cfg_attr(feature = "nightly_doc", doc(cfg(all(feature = "error", feature = "time"))))]
34mod full_composite {
35 use super::*;
36 use crate::{DataOverflow, DOC_DATA_OVERFLOW};
37
38 #[doc = crate::TAG_RESULT!()]
39 pub type TimeResult<T> = crate::Result<T, TimeError>;
41
42 impl_error! { composite: fmt(f)
43 #[non_exhaustive]
45 pub enum TimeError {
46 DOC_DATA_OVERFLOW:
47 DataOverflow(o|0: Option<usize>) => DataOverflow(*o),
48
49 #[cfg(feature = "std")]
50 #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "std")))]
51 DOC_SYSTEM_TIME_ERROR:
52 SystemTime(d|0: Duration) => SystemTimeError(*d),
53 }
54 }
55 #[cfg(feature = "std")]
56 #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "std")))]
57 impl From<StdSystemTimeError> for TimeError {
58 fn from(from: StdSystemTimeError) -> Self {
59 TimeError::SystemTime(from.duration())
60 }
61 }
62}