From 6ebdf7e33014107da76b0222db1ff3978902441c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 18 Sep 2023 16:59:38 +0200 Subject: [PATCH 01/10] added packet ID trait impls --- CHANGELOG.md | 4 ++++ src/lib.rs | 24 +++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0453cc0..ca03124 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). # [unreleased] +## Added + +- `PacketId` trait impls: `Ord`, `PartialOrd` and `Hash` + # [v0.7.0-beta.1] 2023-08-28 - Bump `zerocopy` dependency to v0.7.0 diff --git a/src/lib.rs b/src/lib.rs index df09922..509aa81 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -62,7 +62,10 @@ extern crate alloc; extern crate std; use crate::ecss::CCSDS_HEADER_LEN; -use core::fmt::{Debug, Display, Formatter}; +use core::{ + fmt::{Debug, Display, Formatter}, + hash::Hash, +}; use crc::{Crc, CRC_16_IBM_3740}; use delegate::delegate; @@ -195,6 +198,25 @@ pub struct PacketId { apid: u16, } +impl PartialOrd for PacketId { + fn partial_cmp(&self, other: &Self) -> Option { + self.raw().partial_cmp(&other.raw()) + } +} + +impl Ord for PacketId { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.raw().cmp(&other.raw()) + } +} + +impl Hash for PacketId { + fn hash(&self, state: &mut H) { + let raw = self.raw(); + raw.hash(state); + } +} + impl Default for PacketId { fn default() -> Self { PacketId { From 6116cdb27c2608eef29d61d3dca8a32010fdf165 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 18 Sep 2023 17:13:22 +0200 Subject: [PATCH 02/10] add some tests --- src/lib.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 509aa81..bbd38e3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -743,6 +743,8 @@ pub mod zc { #[cfg(all(test, feature = "std"))] mod tests { + use std::collections::HashSet; + #[cfg(feature = "serde")] use crate::CcsdsPrimaryHeader; use crate::{ @@ -1056,4 +1058,22 @@ mod tests { assert_eq!(sp_header.ptype(), PacketType::Tc); assert_eq!(sp_header.data_len(), 0); } + + #[test] + fn packet_id_ord_partial_ord() { + let packet_id_small = PacketId::from(1_u16); + let packet_id_larger = PacketId::from(2_u16); + assert!(packet_id_small < packet_id_larger); + assert!(packet_id_larger > packet_id_small); + assert_eq!( + packet_id_small.cmp(&packet_id_larger), + core::cmp::Ordering::Less + ); + } + + #[test] + fn packet_id_hashable() { + let mut id_set = HashSet::new(); + id_set.insert(PacketId::from(1_u16)); + } } From a4b14250c28497662e80e7762fb4d5a8f500358c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 18 Sep 2023 17:32:54 +0200 Subject: [PATCH 03/10] add stage to display toolchain info --- automation/Jenkinsfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/automation/Jenkinsfile b/automation/Jenkinsfile index 41c4d46..f056948 100644 --- a/automation/Jenkinsfile +++ b/automation/Jenkinsfile @@ -8,6 +8,10 @@ pipeline { } stages { + stage ('Rust Toolchain Info') { + def rustVersion =sh(script: 'rustc --version', returnStatus: true).trim() + echo "Rust Toolchain Vrsion: ${rustVersion}" + } stage('Clippy') { steps { sh 'cargo clippy' From 2a0db6b21ca98302f74599132a54d67a7cfc8f69 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 18 Sep 2023 17:34:04 +0200 Subject: [PATCH 04/10] maybe this fixes the issue? --- src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index bbd38e3..a55e5da 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -190,7 +190,7 @@ impl TryFrom for SequenceFlags { /// Abstraction for the CCSDS Packet ID, which forms the last thirteen bits /// of the first two bytes in the CCSDS primary header. -#[derive(Debug, PartialEq, Eq, Copy, Clone)] +#[derive(Debug, Eq, Copy, Clone)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct PacketId { pub ptype: PacketType, @@ -198,6 +198,12 @@ pub struct PacketId { apid: u16, } +impl PartialEq for PacketId { + fn eq(&self, other: &Self) -> bool { + self.raw().eq(&other.raw()) + } +} + impl PartialOrd for PacketId { fn partial_cmp(&self, other: &Self) -> Option { self.raw().partial_cmp(&other.raw()) From 963b9dbb5fcd963043a774bc1f1a119a32c57d90 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 18 Sep 2023 17:34:49 +0200 Subject: [PATCH 05/10] inline PacketId raw call --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index a55e5da..ec2bcd1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -283,6 +283,7 @@ impl PacketId { self.apid } + #[inline] pub fn raw(&self) -> u16 { ((self.ptype as u16) << 12) | ((self.sec_header_flag as u16) << 11) | self.apid } From 90e48483bb09d7f84ae2c9b40c04b07777e23c36 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 18 Sep 2023 17:36:10 +0200 Subject: [PATCH 06/10] next try --- automation/Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/automation/Jenkinsfile b/automation/Jenkinsfile index f056948..c345509 100644 --- a/automation/Jenkinsfile +++ b/automation/Jenkinsfile @@ -8,8 +8,8 @@ pipeline { } stages { - stage ('Rust Toolchain Info') { - def rustVersion =sh(script: 'rustc --version', returnStatus: true).trim() + stage('Rust Toolchain Info') { + def rustVersion = sh(script: 'rustc --version', returnStatus: true).trim() echo "Rust Toolchain Vrsion: ${rustVersion}" } stage('Clippy') { From b94d07f6c96edf5e9352d39811d20378aa608be4 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 18 Sep 2023 17:38:56 +0200 Subject: [PATCH 07/10] try 2 --- automation/Jenkinsfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/automation/Jenkinsfile b/automation/Jenkinsfile index c345509..9b40ccb 100644 --- a/automation/Jenkinsfile +++ b/automation/Jenkinsfile @@ -9,8 +9,10 @@ pipeline { stages { stage('Rust Toolchain Info') { - def rustVersion = sh(script: 'rustc --version', returnStatus: true).trim() - echo "Rust Toolchain Vrsion: ${rustVersion}" + steps { + def rustVersion = sh(script: 'rustc --version', returnStatus: true).trim() + echo "Rust Toolchain Vrsion: ${rustVersion}" + } } stage('Clippy') { steps { From 5d8b5ce370d46983619bee4499aeffd0fd75e834 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 18 Sep 2023 17:42:10 +0200 Subject: [PATCH 08/10] please stop --- automation/Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/automation/Jenkinsfile b/automation/Jenkinsfile index 9b40ccb..c2050cc 100644 --- a/automation/Jenkinsfile +++ b/automation/Jenkinsfile @@ -10,8 +10,8 @@ pipeline { stages { stage('Rust Toolchain Info') { steps { - def rustVersion = sh(script: 'rustc --version', returnStatus: true).trim() - echo "Rust Toolchain Vrsion: ${rustVersion}" + echo "Rust Toolchain Version" + sh 'rustc --version' } } stage('Clippy') { From a6bced7983b7dafe5416b85153cc4a902dab40c3 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 18 Sep 2023 17:50:50 +0200 Subject: [PATCH 09/10] this is okay --- automation/Jenkinsfile | 1 - 1 file changed, 1 deletion(-) diff --git a/automation/Jenkinsfile b/automation/Jenkinsfile index c2050cc..b9d4ea4 100644 --- a/automation/Jenkinsfile +++ b/automation/Jenkinsfile @@ -10,7 +10,6 @@ pipeline { stages { stage('Rust Toolchain Info') { steps { - echo "Rust Toolchain Version" sh 'rustc --version' } } From be37c15478198ace54ce552333f9dba6c9051da9 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 18 Sep 2023 18:00:14 +0200 Subject: [PATCH 10/10] docs failure should not fail the whole build --- automation/Jenkinsfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/automation/Jenkinsfile b/automation/Jenkinsfile index b9d4ea4..7b7d35c 100644 --- a/automation/Jenkinsfile +++ b/automation/Jenkinsfile @@ -20,7 +20,9 @@ pipeline { } stage('Docs') { steps { - sh 'cargo +nightly doc --all-features' + catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') { + sh 'cargo +nightly doc --all-features' + } } } stage('Rustfmt') {