jiff/error/
signed_duration.rs1use crate::{Unit, error};
2
3#[derive(#[automatically_derived]impl ::core::clone::Clone for Error {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
match self {
Self::ConvertNonFinite => Error::ConvertNonFinite,
Self::ConvertSystemTime => Error::ConvertSystemTime,
Self::RoundOverflowed { unit: __self_0 } =>
Error::RoundOverflowed {
unit: ::core::clone::Clone::clone(__self_0),
},
}
}
}Clone, #[automatically_derived]impl ::core::fmt::Debug for Error {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::ConvertNonFinite =>
::core::fmt::Formatter::write_str(f, "ConvertNonFinite"),
Self::ConvertSystemTime =>
::core::fmt::Formatter::write_str(f, "ConvertSystemTime"),
Self::RoundOverflowed { unit: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"RoundOverflowed unit", &__self_0),
}
}
}Debug)]
4#[cfg_attr(feature = "defmt", derive(defmt::Format))]
5pub(crate) enum Error {
6 ConvertNonFinite,
7 ConvertSystemTime,
8 RoundOverflowed { unit: Unit },
9}
10
11impl 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
19impl error::IntoError for Error {
20 fn into_error(self) -> error::Error {
21 self.into()
22 }
23}
24
25impl 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 } => f.write_fmt(format_args!("rounding signed duration to nearest {0} resulted in a value outside the supported range of a `jiff::SignedDuration`",
unit.singular()))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}