implement thiserror::Error for StdTimestampError
This commit is contained in:
parent
2704c589be
commit
b5bea3e1c6
@ -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"
|
||||
|
@ -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;
|
||||
|
@ -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};
|
||||
|
@ -71,40 +71,6 @@ pub enum TimestampError {
|
||||
CustomEpochNotSupported,
|
||||
}
|
||||
|
||||
impl From<cds::CdsError> for TimestampError {
|
||||
fn from(e: cds::CdsError) -> Self {
|
||||
TimestampError::CdsError(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<cuc::CucError> 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<TimestampError> for StdTimestampError {
|
||||
fn from(v: TimestampError) -> Self {
|
||||
Self::TimestampError(v)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl From<SystemTimeError> 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<cds::CdsError> for TimestampError {
|
||||
fn from(e: cds::CdsError) -> Self {
|
||||
TimestampError::CdsError(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<cuc::CucError> 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")))]
|
||||
|
Loading…
Reference in New Issue
Block a user