Merge remote-tracking branch 'origin/main' into more-granular-error-handling
This commit is contained in:
commit
8b151d942d
@ -62,4 +62,4 @@ timelib = ["dep:time"]
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
rustdoc-args = ["--cfg", "doc_cfg", "--generate-link-to-definition"]
|
||||
rustdoc-args = ["--cfg", "docsrs", "--generate-link-to-definition"]
|
||||
|
@ -4,7 +4,7 @@ Checklist for new releases
|
||||
# Pre-Release
|
||||
|
||||
1. Make sure any new modules are documented sufficiently enough and check docs with
|
||||
`cargo +nightly doc --all-features --config 'rustdocflags=["--cfg", "doc_cfg"]' --open`.
|
||||
`cargo +nightly doc --all-features --config 'build.rustdocflags=["--cfg", "docsrs"]' --open`.
|
||||
2. Bump version specifier in `Cargo.toml`.
|
||||
3. Update `CHANGELOG.md`: Convert `unreleased` section into version section with date and add new
|
||||
`unreleased` section.
|
||||
|
@ -88,7 +88,6 @@ impl<'data> Lv<'data> {
|
||||
/// Helper function to build a string LV. This is especially useful for the file or directory
|
||||
/// path LVs
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
pub fn new_from_string(string: &'data String) -> Result<Lv<'data>, TlvLvError> {
|
||||
Self::new(string.as_bytes())
|
||||
}
|
||||
|
@ -374,7 +374,6 @@ pub mod legacy_tc {
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
|
||||
pub fn append_to_vec(&self, vec: &mut Vec<u8>) -> Result<usize, PusError> {
|
||||
let sph_zc = crate::zc::SpHeader::from(self.sp_header);
|
||||
let appended_len = PUS_TC_MIN_LEN_WITHOUT_APP_DATA + self.app_data.len();
|
||||
|
@ -341,7 +341,6 @@ pub mod legacy_tm {
|
||||
|
||||
/// Append the raw PUS byte representation to a provided [alloc::vec::Vec]
|
||||
#[cfg(feature = "alloc")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
|
||||
pub fn append_to_vec(&self, vec: &mut Vec<u8>) -> Result<usize, PusError> {
|
||||
let sph_zc = crate::zc::SpHeader::from(self.sp_header);
|
||||
let mut appended_len = PUS_TM_MIN_LEN_WITHOUT_SOURCE_DATA;
|
||||
@ -693,7 +692,6 @@ impl<'raw_data> PusTmCreator<'raw_data> {
|
||||
|
||||
/// Append the raw PUS byte representation to a provided [alloc::vec::Vec]
|
||||
#[cfg(feature = "alloc")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
|
||||
pub fn append_to_vec(&self, vec: &mut Vec<u8>) -> Result<usize, PusError> {
|
||||
let sph_zc = crate::zc::SpHeader::from(self.sp_header);
|
||||
let mut appended_len = PUS_TM_MIN_LEN_WITHOUT_SOURCE_DATA + self.sec_header.timestamp.len();
|
||||
|
@ -55,7 +55,7 @@
|
||||
//! println!("{:x?}", &ccsds_buf[0..6]);
|
||||
//! ```
|
||||
#![no_std]
|
||||
#![cfg_attr(doc_cfg, feature(doc_cfg))]
|
||||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
||||
#[cfg(feature = "alloc")]
|
||||
extern crate alloc;
|
||||
#[cfg(any(feature = "std", test))]
|
||||
|
@ -40,13 +40,11 @@ pub mod alloc_mod_chrono {
|
||||
};
|
||||
|
||||
/// Generates a time code formatter using the [FMT_STR_CODE_A_WITH_SIZE] format.
|
||||
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "alloc", feature = "chrono"))))]
|
||||
pub fn generate_time_code_a(date: &DateTime<Utc>) -> DelayedFormat<StrftimeItems<'static>> {
|
||||
date.format(FMT_STR_CODE_A_WITH_SIZE.0)
|
||||
}
|
||||
|
||||
/// Generates a time code formatter using the [FMT_STR_CODE_A_TERMINATED_WITH_SIZE] format.
|
||||
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "alloc", feature = "chrono"))))]
|
||||
pub fn generate_time_code_a_terminated(
|
||||
date: &DateTime<Utc>,
|
||||
) -> DelayedFormat<StrftimeItems<'static>> {
|
||||
@ -54,13 +52,11 @@ pub mod alloc_mod_chrono {
|
||||
}
|
||||
|
||||
/// Generates a time code formatter using the [FMT_STR_CODE_B_WITH_SIZE] format.
|
||||
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "alloc", feature = "chrono"))))]
|
||||
pub fn generate_time_code_b(date: &DateTime<Utc>) -> DelayedFormat<StrftimeItems<'static>> {
|
||||
date.format(FMT_STR_CODE_B_WITH_SIZE.0)
|
||||
}
|
||||
|
||||
/// Generates a time code formatter using the [FMT_STR_CODE_B_TERMINATED_WITH_SIZE] format.
|
||||
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "alloc", feature = "chrono"))))]
|
||||
pub fn generate_time_code_b_terminated(
|
||||
date: &DateTime<Utc>,
|
||||
) -> DelayedFormat<StrftimeItems<'static>> {
|
||||
|
@ -451,13 +451,10 @@ impl CdsConverter for ConversionFromNow {
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
|
||||
pub trait DynCdsTimeProvider: CcsdsTimeProvider + CdsTimestamp + TimeWriter + Any {}
|
||||
#[cfg(feature = "alloc")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
|
||||
impl DynCdsTimeProvider for CdsTime<DaysLen16Bits> {}
|
||||
#[cfg(feature = "alloc")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
|
||||
impl DynCdsTimeProvider for CdsTime<DaysLen24Bits> {}
|
||||
|
||||
/// This function returns the correct [CdsTime] instance from a raw byte array
|
||||
@ -487,7 +484,6 @@ impl DynCdsTimeProvider for CdsTime<DaysLen24Bits> {}
|
||||
/// }
|
||||
/// ```
|
||||
#[cfg(feature = "alloc")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
|
||||
pub fn get_dyn_time_provider_from_bytes(
|
||||
buf: &[u8],
|
||||
) -> Result<Box<dyn DynCdsTimeProvider>, TimestampError> {
|
||||
@ -791,7 +787,6 @@ impl<ProvidesDaysLen: ProvidesDaysLength> CdsTime<ProvidesDaysLen> {
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
pub fn update_from_now(&mut self) -> Result<(), StdTimestampError> {
|
||||
let conversion_from_now = self.generic_conversion_from_now()?;
|
||||
let ccsds_days: ProvidesDaysLen::FieldType = conversion_from_now
|
||||
@ -827,7 +822,6 @@ impl CdsTime<DaysLen24Bits> {
|
||||
|
||||
/// Generate a time stamp from the current time using the system clock.
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
pub fn from_now_with_u24_days() -> Result<Self, StdTimestampError> {
|
||||
Self::from_now_generic(LengthOfDaySegment::Long24Bits)
|
||||
}
|
||||
@ -876,14 +870,12 @@ impl CdsTime<DaysLen24Bits> {
|
||||
|
||||
/// Like [Self::from_now_with_u24_days] but with microsecond sub-millisecond precision.
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
pub fn from_now_with_u24_days_us_precision() -> Result<Self, StdTimestampError> {
|
||||
Self::from_now_generic_us_prec(LengthOfDaySegment::Long24Bits)
|
||||
}
|
||||
|
||||
/// Like [Self::from_now_with_u24_days] but with picoseconds sub-millisecond precision.
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
pub fn from_now_with_u24_days_ps_precision() -> Result<Self, StdTimestampError> {
|
||||
Self::from_now_generic_us_prec(LengthOfDaySegment::Long24Bits)
|
||||
}
|
||||
@ -934,7 +926,6 @@ impl CdsTime<DaysLen16Bits> {
|
||||
|
||||
/// Generate a time stamp from the current time using the system clock.
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
pub fn from_now_with_u16_days() -> Result<Self, StdTimestampError> {
|
||||
Self::from_now_generic(LengthOfDaySegment::Short16Bits)
|
||||
}
|
||||
@ -971,14 +962,12 @@ impl CdsTime<DaysLen16Bits> {
|
||||
|
||||
/// Like [Self::from_now_with_u16_days] but with microsecond sub-millisecond precision.
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
pub fn from_now_with_u16_days_us_precision() -> Result<Self, StdTimestampError> {
|
||||
Self::from_now_generic_us_prec(LengthOfDaySegment::Short16Bits)
|
||||
}
|
||||
|
||||
/// Like [Self::from_now_with_u16_days] but with picosecond sub-millisecond precision.
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
pub fn from_now_with_u16_days_ps_precision() -> Result<Self, StdTimestampError> {
|
||||
Self::from_now_generic_ps_prec(LengthOfDaySegment::Short16Bits)
|
||||
}
|
||||
|
@ -359,7 +359,6 @@ impl CucTime {
|
||||
/// must be applied on top of the UTC based time retrieved from the system in addition to the
|
||||
/// conversion to the CCSDS epoch.
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
pub fn from_now(
|
||||
fraction_resolution: FractionalResolution,
|
||||
leap_seconds: u32,
|
||||
@ -391,7 +390,6 @@ impl CucTime {
|
||||
/// must be applied on top of the UTC based time retrieved from the system in addition to the
|
||||
/// conversion to the CCSDS epoch.
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
pub fn update_from_now(&mut self, leap_seconds: u32) -> Result<(), StdTimestampError> {
|
||||
let now = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?;
|
||||
self.counter.1 = unix_epoch_to_ccsds_epoch(now.as_secs() as i64) as u32;
|
||||
@ -411,7 +409,6 @@ impl CucTime {
|
||||
}
|
||||
|
||||
#[cfg(feature = "chrono")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "chrono")))]
|
||||
pub fn from_chrono_date_time(
|
||||
dt: &chrono::DateTime<chrono::Utc>,
|
||||
res: FractionalResolution,
|
||||
|
@ -137,7 +137,6 @@ impl From<cuc::CucError> for TimestampError {
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
pub mod std_mod {
|
||||
use crate::time::TimestampError;
|
||||
use std::time::SystemTimeError;
|
||||
@ -145,7 +144,7 @@ pub mod std_mod {
|
||||
|
||||
#[derive(Debug, Clone, Error)]
|
||||
pub enum StdTimestampError {
|
||||
#[error("system time error: {0}")]
|
||||
#[error("system time error: {0:?}")]
|
||||
SystemTime(#[from] SystemTimeError),
|
||||
#[error("timestamp error: {0}")]
|
||||
Timestamp(#[from] TimestampError),
|
||||
@ -153,7 +152,6 @@ pub mod std_mod {
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
pub fn seconds_since_epoch() -> f64 {
|
||||
SystemTime::now()
|
||||
.duration_since(SystemTime::UNIX_EPOCH)
|
||||
@ -188,7 +186,6 @@ pub const fn ccsds_epoch_to_unix_epoch(ccsds_epoch: i64) -> i64 {
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
pub fn ms_of_day_using_sysclock() -> u32 {
|
||||
ms_of_day(seconds_since_epoch())
|
||||
}
|
||||
@ -209,7 +206,6 @@ pub trait TimeWriter {
|
||||
fn write_to_bytes(&self, bytes: &mut [u8]) -> Result<usize, TimestampError>;
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
|
||||
fn to_vec(&self) -> Result<alloc::vec::Vec<u8>, TimestampError> {
|
||||
let mut vec = alloc::vec![0; self.len_written()];
|
||||
self.write_to_bytes(&mut vec)?;
|
||||
@ -248,13 +244,11 @@ pub trait CcsdsTimeProvider {
|
||||
}
|
||||
|
||||
#[cfg(feature = "chrono")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "chrono")))]
|
||||
fn chrono_date_time(&self) -> chrono::LocalResult<chrono::DateTime<chrono::Utc>> {
|
||||
chrono::Utc.timestamp_opt(self.unix_secs(), self.subsec_nanos())
|
||||
}
|
||||
|
||||
#[cfg(feature = "timelib")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "timelib")))]
|
||||
fn timelib_date_time(&self) -> Result<time::OffsetDateTime, time::error::ComponentRange> {
|
||||
Ok(time::OffsetDateTime::from_unix_timestamp(self.unix_secs())?
|
||||
+ time::Duration::nanoseconds(self.subsec_nanos().into()))
|
||||
@ -351,7 +345,6 @@ impl UnixTime {
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
pub fn from_now() -> Result<Self, SystemTimeError> {
|
||||
let now = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?;
|
||||
let epoch = now.as_secs();
|
||||
@ -368,13 +361,11 @@ impl UnixTime {
|
||||
}
|
||||
|
||||
#[cfg(feature = "chrono")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "chrono")))]
|
||||
pub fn chrono_date_time(&self) -> chrono::LocalResult<chrono::DateTime<chrono::Utc>> {
|
||||
Utc.timestamp_opt(self.secs, self.subsec_nanos)
|
||||
}
|
||||
|
||||
#[cfg(feature = "timelib")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "timelib")))]
|
||||
pub fn timelib_date_time(&self) -> Result<time::OffsetDateTime, time::error::ComponentRange> {
|
||||
Ok(time::OffsetDateTime::from_unix_timestamp(self.secs())?
|
||||
+ time::Duration::nanoseconds(self.subsec_nanos().into()))
|
||||
@ -395,7 +386,6 @@ impl UnixTime {
|
||||
}
|
||||
|
||||
#[cfg(feature = "chrono")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "chrono")))]
|
||||
impl From<chrono::DateTime<chrono::Utc>> for UnixTime {
|
||||
fn from(value: chrono::DateTime<chrono::Utc>) -> Self {
|
||||
Self::new(value.timestamp(), value.timestamp_subsec_nanos())
|
||||
@ -403,7 +393,6 @@ impl From<chrono::DateTime<chrono::Utc>> for UnixTime {
|
||||
}
|
||||
|
||||
#[cfg(feature = "timelib")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "timelib")))]
|
||||
impl From<time::OffsetDateTime> for UnixTime {
|
||||
fn from(value: time::OffsetDateTime) -> Self {
|
||||
Self::new(value.unix_timestamp(), value.nanosecond())
|
||||
|
@ -77,7 +77,6 @@ pub trait UnsignedEnum {
|
||||
fn value(&self) -> u64;
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
|
||||
fn to_vec(&self) -> alloc::vec::Vec<u8> {
|
||||
let mut buf = alloc::vec![0; self.size()];
|
||||
self.write_to_be_bytes(&mut buf).unwrap();
|
||||
|
Loading…
Reference in New Issue
Block a user