diff --git a/src/time/cds.rs b/src/time/cds.rs index 3db55bd..de4cc40 100644 --- a/src/time/cds.rs +++ b/src/time/cds.rs @@ -428,14 +428,17 @@ pub fn get_dyn_time_provider_from_bytes( ) -> Result, TimestampError> { let time_code = ccsds_time_code_from_p_field(buf[0]); if let Err(e) = time_code { - return Err(TimestampError::InvalidTimeCode(CcsdsTimeCodes::Cds, e)); + return Err(TimestampError::InvalidTimeCode { + expected: CcsdsTimeCodes::Cds, + found: e, + }); } let time_code = time_code.unwrap(); if time_code != CcsdsTimeCodes::Cds { - return Err(TimestampError::InvalidTimeCode( - CcsdsTimeCodes::Cds, - time_code as u8, - )); + return Err(TimestampError::InvalidTimeCode { + expected: CcsdsTimeCodes::Cds, + found: time_code as u8, + }); } if length_of_day_segment_from_pfield(buf[0]) == LengthOfDaySegment::Short16Bits { Ok(Box::new(TimeProvider::from_bytes_with_u16_days(buf)?)) @@ -523,17 +526,17 @@ impl TimeProvider { Ok(cds_type) => match cds_type { CcsdsTimeCodes::Cds => (), _ => { - return Err(TimestampError::InvalidTimeCode( - CcsdsTimeCodes::Cds, - cds_type as u8, - )) + return Err(TimestampError::InvalidTimeCode { + expected: CcsdsTimeCodes::Cds, + found: cds_type as u8, + }) } }, _ => { - return Err(TimestampError::InvalidTimeCode( - CcsdsTimeCodes::Cds, - pfield >> 4 & 0b111, - )) + return Err(TimestampError::InvalidTimeCode { + expected: CcsdsTimeCodes::Cds, + found: pfield >> 4 & 0b111, + }); } }; if ((pfield >> 3) & 0b1) == 1 { diff --git a/src/time/cuc.rs b/src/time/cuc.rs index 22d3b6f..e7a090b 100644 --- a/src/time/cuc.rs +++ b/src/time/cuc.rs @@ -463,17 +463,17 @@ impl TimeReader for TimeProviderCcsdsEpoch { match ccsds_time_code_from_p_field(buf[0]) { Ok(code) => { if code != CcsdsTimeCodes::CucCcsdsEpoch { - return Err(TimestampError::InvalidTimeCode( - CcsdsTimeCodes::CucCcsdsEpoch, - code as u8, - )); + return Err(TimestampError::InvalidTimeCode { + expected: CcsdsTimeCodes::CucCcsdsEpoch, + found: code as u8, + }); } } Err(raw) => { - return Err(TimestampError::InvalidTimeCode( - CcsdsTimeCodes::CucCcsdsEpoch, - raw, - )) + return Err(TimestampError::InvalidTimeCode { + expected: CcsdsTimeCodes::CucCcsdsEpoch, + found: raw, + }); } } let (cntr_len, fractions_len, total_len) = diff --git a/src/time/mod.rs b/src/time/mod.rs index dbfe995..9350499 100644 --- a/src/time/mod.rs +++ b/src/time/mod.rs @@ -5,6 +5,7 @@ use core::cmp::Ordering; use core::fmt::{Display, Formatter}; use core::ops::{Add, AddAssign}; use core::time::Duration; +use core::u8; #[allow(unused_imports)] #[cfg(not(feature = "std"))] @@ -63,9 +64,7 @@ pub fn ccsds_time_code_from_p_field(pfield: u8) -> Result { #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[non_exhaustive] pub enum TimestampError { - /// Contains tuple where first value is the expected time code and the second - /// value is the found raw value - InvalidTimeCode(CcsdsTimeCodes, u8), + InvalidTimeCode { expected: CcsdsTimeCodes, found: u8 }, ByteConversion(ByteConversionError), Cds(cds::CdsError), Cuc(cuc::CucError), @@ -76,10 +75,10 @@ pub enum TimestampError { impl Display for TimestampError { fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { match self { - TimestampError::InvalidTimeCode(time_code, raw_val) => { + TimestampError::InvalidTimeCode { expected, found } => { write!( f, - "invalid raw time code value {raw_val} for time code {time_code:?}" + "invalid raw time code value {found} for time code {expected:?}" ) } TimestampError::Cds(e) => {