add EcssEnumerationExt trait extension

This commit is contained in:
Robin Müller 2022-10-31 00:22:28 +01:00
parent 65e85f20e0
commit d391891991
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC

View File

@ -1,5 +1,6 @@
//! Common definitions and helpers required to create PUS TMTC packets according to
//! [ECSS-E-ST-70-41C](https://ecss.nl/standard/ecss-e-st-70-41c-space-engineering-telemetry-and-telecommand-packet-utilization-15-april-2016/)
use core::fmt::Debug;
use crate::{ByteConversionError, CcsdsPacket, SizeMissmatch};
use core::mem::size_of;
use crc::{Crc, CRC_16_IBM_3740};
@ -171,6 +172,8 @@ pub trait EcssEnumeration {
fn write_to_bytes(&self, buf: &mut [u8]) -> Result<(), ByteConversionError>;
}
pub trait EcssEnumerationExt: EcssEnumeration + Debug + Copy + Clone + PartialEq + Eq {}
pub trait ToBeBytes {
type ByteArray: AsRef<[u8]>;
fn to_be_bytes(&self) -> Self::ByteArray;
@ -208,6 +211,7 @@ impl ToBeBytes for u64 {
}
}
#[derive (Debug, Copy, Clone, Eq, PartialEq)]
pub struct GenericEcssEnumWrapper<TYPE> {
val: TYPE,
}
@ -239,6 +243,8 @@ impl<TYPE: ToBeBytes> EcssEnumeration for GenericEcssEnumWrapper<TYPE> {
}
}
impl<TYPE: Debug + Copy + Clone + PartialEq + Eq + ToBeBytes> EcssEnumerationExt for GenericEcssEnumWrapper<TYPE> {}
pub type EcssEnumU8 = GenericEcssEnumWrapper<u8>;
pub type EcssEnumU16 = GenericEcssEnumWrapper<u16>;
pub type EcssEnumU32 = GenericEcssEnumWrapper<u32>;