1use core::fmt;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
10#[must_use = "errors must be handled; use `?` or `match` to inspect the failure"]
11#[non_exhaustive]
12pub enum GnssTimeError {
13 Overflow,
15
16 InvalidInput(&'static str),
20
21 LeapSecondsRequired,
23}
24
25impl fmt::Display for GnssTimeError {
26 fn fmt(
27 &self,
28 f: &mut fmt::Formatter<'_>,
29 ) -> fmt::Result {
30 match self {
31 GnssTimeError::Overflow => {
32 f.write_str("nanosecond arithmetic overflowed the u64 range")
33 }
34 GnssTimeError::InvalidInput(msg) => {
35 write!(f, "invalid input: {msg}")
36 }
37 GnssTimeError::LeapSecondsRequired => f.write_str(
38 "this conversion requires a LeapSeconds context \
39 (GLONASS <-> GPS or GPS <-> UTC)",
40 ),
41 }
42 }
43}
44
45#[cfg(feature = "std")]
47impl std::error::Error for GnssTimeError {}
48
49#[cfg(feature = "defmt")]
51impl defmt::Format for GnssTimeError {
52 fn format(
53 &self,
54 f: defmt::Formatter,
55 ) {
56 match self {
57 GnssTimeError::Overflow => {
58 defmt::write!(f, "nanosecond arithmetic overflowed the u64 range")
59 }
60 GnssTimeError::InvalidInput(msg) => {
61 defmt::write!(f, "invalid input: {}", msg)
62 }
63 GnssTimeError::LeapSecondsRequired => {
64 defmt::write!(f, "conversion requires LeapSeconds context")
65 }
66 }
67 }
68}