Debian Codegraph @

debian/rust-vendor/jiff/src/error/signed_duration.rs

raw
1 use crate::{error, Unit};
2
3 #[derive(Clone, Debug)]
4 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
5 pub(crate) enum Error {
6 ConvertNonFinite,
7 ConvertSystemTime,
8 RoundOverflowed { unit: Unit },
9 }
10
11 impl From<Error> for error::Error {
12 #[cold]
13 #[inline(never)]
14 fn from(err: Error) -> error::Error {
15 error::ErrorKind::SignedDuration(err).into()
16 }
17 }
18
19 impl error::IntoError for Error {
20 fn into_error(self) -> error::Error {
21 self.into()
22 }
23 }
24
25 impl core::fmt::Display for Error {
26 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
27 use self::Error::*;
28
29 match *self {
30 ConvertNonFinite => f.write_str(
31 "could not convert non-finite \
32 floating point seconds to signed duration \
33 (floating point seconds must be finite)",
34 ),
35 ConvertSystemTime => f.write_str(
36 "failed to get duration between \
37 `std::time::SystemTime` values",
38 ),
39 RoundOverflowed { unit } => write!(
40 f,
41 "rounding signed duration to nearest {singular} \
42 resulted in a value outside the supported range \
43 of a `jiff::SignedDuration`",
44 singular = unit.singular(),
45 ),
46 }
47 }
48 }