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