use alloc::collections::TryReserveError; use embassy_rp::rtc::RtcError; use sachy_sntp::SntpError; #[derive(Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum PicoError { InvalidSntpTime(SntpError), InvalidRtcTime, AllocationError, } impl core::fmt::Display for PicoError { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { PicoError::InvalidSntpTime(reason) => write!(f, "Invalid SNTP time: {reason:?}"), PicoError::InvalidRtcTime => write!(f, "Invalid RTC time: Year is out of bounds"), PicoError::AllocationError => write!(f, "Failed to allocate memory"), } } } impl core::error::Error for PicoError {} impl From for PicoError { fn from(value: SntpError) -> Self { Self::InvalidSntpTime(value) } } impl From for PicoError { fn from(_value: RtcError) -> Self { Self::InvalidRtcTime } } impl From for PicoError { fn from(_value: TryReserveError) -> Self { Self::AllocationError } }