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 {