use core::fmt::{self};
#[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,
OutOfRange,
}
impl fmt::Display for GnssTimeError {
fn fmt(
&self,
f: &mut fmt::Formatter<'_>,
) -> fmt::Result {
match self {
GnssTimeError::Overflow => f.write_str("arithmetic overflow in nanoseconds"),
GnssTimeError::InvalidInput(msg) => {
write!(f, "invalid input: {msg}")
}
GnssTimeError::LeapSecondsRequired => f.write_str("leap-second data required"),
GnssTimeError::OutOfRange => f.write_str("timestamp is out of representable range"),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for GnssTimeError {}
#[cfg(feature = "defmt")]
#[allow(clippy::match_same_arms)]
impl defmt::Format for GnssTimeError {
fn format(
&self,
f: defmt::Formatter,
) {
match self {
GnssTimeError::Overflow => {
defmt::write!(f, "arithmetic overflow in nanoseconds");
}
GnssTimeError::InvalidInput(msg) => {
defmt::write!(f, "invalid input: {}", msg);
}
GnssTimeError::LeapSecondsRequired => {
defmt::write!(f, "leap-second data required");
}
GnssTimeError::OutOfRange => {
defmt::write!(f, "timestamp is out of representable range");
}
}
}
}