added packet ID trait impls
Some checks failed
Rust/spacepackets/pipeline/head There was a failure building this commit

This commit is contained in:
Robin Müller 2023-09-18 16:59:38 +02:00
parent e935b3825a
commit 6ebdf7e330
Signed by: muellerr
GPG Key ID: A649FB78196E3849
2 changed files with 27 additions and 1 deletions

View File

@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
# [unreleased] # [unreleased]
## Added
- `PacketId` trait impls: `Ord`, `PartialOrd` and `Hash`
# [v0.7.0-beta.1] 2023-08-28 # [v0.7.0-beta.1] 2023-08-28
- Bump `zerocopy` dependency to v0.7.0 - Bump `zerocopy` dependency to v0.7.0

View File

@ -62,7 +62,10 @@ extern crate alloc;
extern crate std; extern crate std;
use crate::ecss::CCSDS_HEADER_LEN; 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 crc::{Crc, CRC_16_IBM_3740};
use delegate::delegate; use delegate::delegate;
@ -195,6 +198,25 @@ pub struct PacketId {
apid: u16, apid: u16,
} }
impl PartialOrd for PacketId {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
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<H: core::hash::Hasher>(&self, state: &mut H) {
let raw = self.raw();
raw.hash(state);
}
}
impl Default for PacketId { impl Default for PacketId {
fn default() -> Self { fn default() -> Self {
PacketId { PacketId {