use core::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[must_use = "errors must be handled; use `?` or `match` to inspect the failure"]
#[non_exhaustive]
pub enum GnssTimeError {
Overflow,
InvalidInput(&'static str),
LeapSecondsRequired,
}
impl fmt::Display for GnssTimeError {
fn fmt(
&self,
f: &mut fmt::Formatter<'_>,
) -> fmt::Result {
match self {
GnssTimeError::Overflow => {
f.write_str("nanosecond arithmetic overflowed the u64 range")
}
GnssTimeError::InvalidInput(msg) => {
write!(f, "invalid input: {msg}")
}
GnssTimeError::LeapSecondsRequired => f.write_str(
"this conversion requires a LeapSeconds context \
(GLONASS <-> GPS or GPS <-> UTC)",
),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for GnssTimeError {}
#[cfg(feature = "defmt")]
impl defmt::Format for GnssTimeError {
fn format(
&self,
f: defmt::Formatter,
) {
match self {
GnssTimeError::Overflow => {
defmt::write!(f, "nanosecond arithmetic overflowed the u64 range")
}
GnssTimeError::InvalidInput(msg) => {
defmt::write!(f, "invalid input: {}", msg)
}
GnssTimeError::LeapSecondsRequired => {
defmt::write!(f, "conversion requires LeapSeconds context")
}
}
}
}