diff --git a/Cargo.toml b/Cargo.toml index fc3d1c1..cba3583 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ categories = ["aerospace", "aerospace::space-protocols", "no-std", "hardware-sup zerocopy = "0.6" crc = "3" delegate = ">=0.8, <0.11" +thiserror = "1" [dependencies.num_enum] version = "0.6" diff --git a/src/time/cds.rs b/src/time/cds.rs index a5426b7..883363c 100644 --- a/src/time/cds.rs +++ b/src/time/cds.rs @@ -17,6 +17,9 @@ use core::ops::{Add, AddAssign}; use core::time::Duration; use delegate::delegate; +#[cfg(feature = "std")] +use std_mod::*; + /// Base value for the preamble field for a time field parser to determine the time field type. pub const P_FIELD_BASE: u8 = (CcsdsTimeCodes::Cds as u8) << 4; pub const MIN_CDS_FIELD_LEN: usize = 7; diff --git a/src/time/cuc.rs b/src/time/cuc.rs index 95fd01e..bfd7da4 100644 --- a/src/time/cuc.rs +++ b/src/time/cuc.rs @@ -3,6 +3,7 @@ //! //! The core data structure to do this is the [TimeProviderCcsdsEpoch] struct. use super::*; +use crate::time::std_mod::StdTimestampError; use chrono::Datelike; use core::fmt::Debug; use core::ops::{Add, AddAssign}; diff --git a/src/time/mod.rs b/src/time/mod.rs index 2947d7c..f3116ce 100644 --- a/src/time/mod.rs +++ b/src/time/mod.rs @@ -71,40 +71,6 @@ pub enum TimestampError { CustomEpochNotSupported, } -impl From for TimestampError { - fn from(e: cds::CdsError) -> Self { - TimestampError::CdsError(e) - } -} - -impl From for TimestampError { - fn from(e: cuc::CucError) -> Self { - TimestampError::CucError(e) - } -} - -#[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] -#[derive(Debug, Clone)] -pub enum StdTimestampError { - SystemTimeError(SystemTimeError), - TimestampError(TimestampError), -} - -#[cfg(feature = "std")] -impl From for StdTimestampError { - fn from(v: TimestampError) -> Self { - Self::TimestampError(v) - } -} - -#[cfg(feature = "std")] -impl From for StdTimestampError { - fn from(v: SystemTimeError) -> Self { - Self::SystemTimeError(v) - } -} - impl Display for TimestampError { fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { match self { @@ -144,6 +110,33 @@ impl Error for TimestampError { } } } +impl From for TimestampError { + fn from(e: cds::CdsError) -> Self { + TimestampError::CdsError(e) + } +} + +impl From for TimestampError { + fn from(e: cuc::CucError) -> Self { + TimestampError::CucError(e) + } +} + +#[cfg(feature = "std")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] +pub mod std_mod { + use crate::time::TimestampError; + use std::time::SystemTimeError; + use thiserror::Error; + + #[derive(Debug, Clone, Error)] + pub enum StdTimestampError { + #[error("system time error: {0}")] + SystemTimeError(#[from] SystemTimeError), + #[error("timestamp error: {0}")] + TimestampError(#[from] TimestampError), + } +} #[cfg(feature = "std")] #[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]