Fixed PartialEq implementation to PusTc struct #12
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
# Rust
|
||||
/target
|
||||
/Cargo.lock
|
||||
|
||||
# CLion
|
||||
/.idea/*
|
||||
!/.idea/runConfigurations
|
@ -8,6 +8,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
# [unreleased]
|
||||
|
||||
## Added
|
||||
|
||||
- Added `.gitignore`.
|
||||
|
||||
## Fixed
|
||||
|
||||
- Correct manual implementation of Trait `PartialEq` for `PusTc`. The previous auto-derivation was
|
||||
incorrect because it also compared fields unrelated to the raw byte representation.
|
||||
|
||||
# [v0.5.1] 2023-01-22
|
||||
|
||||
## Added
|
||||
|
26
src/tc.rs
26
src/tc.rs
@ -213,7 +213,7 @@ impl PusTcSecondaryHeader {
|
||||
/// serde provider like [postcard](https://docs.rs/postcard/latest/postcard/).
|
||||
///
|
||||
/// There is no spare bytes support yet.
|
||||
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
|
||||
#[derive(Eq, Copy, Clone, Debug)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub struct PusTc<'app_data> {
|
||||
sp_header: SpHeader,
|
||||
@ -440,6 +440,14 @@ impl<'app_data> PusTc<'app_data> {
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for PusTc<'_> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.sp_header == other.sp_header
|
||||
&& self.sec_header == other.sec_header
|
||||
&& self.app_data == other.app_data
|
||||
}
|
||||
}
|
||||
|
||||
//noinspection RsTraitImplementation
|
||||
impl CcsdsPacket for PusTc<'_> {
|
||||
ccsds_impl!();
|
||||
@ -736,4 +744,20 @@ mod tests {
|
||||
assert_eq!(slice[11], 0xee);
|
||||
assert_eq!(slice[12], 0x63);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn partial_eq_pus_tc() {
|
||||
// new vs new simple
|
||||
let pus_tc_1 = base_ping_tc_simple_ctor();
|
||||
let pus_tc_2 = base_ping_tc_full_ctor();
|
||||
assert_eq!(pus_tc_1, pus_tc_2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn partial_eq_serialized_vs_derialized() {
|
||||
let pus_tc = base_ping_tc_simple_ctor();
|
||||
let mut buf = [0; 32];
|
||||
let size = pus_tc.write_to_bytes(&mut buf).unwrap();
|
||||
assert_eq!(pus_tc, PusTc::from_bytes(&buf).unwrap().0);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user