summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@pep.foundation>2019-09-02 11:26:37 +0200
committerNeal H. Walfield <neal@pep.foundation>2019-09-02 13:32:00 +0200
commitd51f9c78b392e8434f3b93b6b6fc93bfb96bfeb1 (patch)
treebd8c1713089793a0c45edfcb5d23a8a7be72b457
parentaa33bd8278cd7f7658bcd60ceeb38ca3d1bd5d7d (diff)
openpgp: Implement Ord for packet::Tag
-rw-r--r--openpgp/src/packet/tag.rs27
1 files changed, 26 insertions, 1 deletions
diff --git a/openpgp/src/packet/tag.rs b/openpgp/src/packet/tag.rs
index 445bcb88..6e6420d5 100644
--- a/openpgp/src/packet/tag.rs
+++ b/openpgp/src/packet/tag.rs
@@ -1,4 +1,5 @@
use std::fmt;
+use std::cmp::Ordering;
use quickcheck::{Arbitrary, Gen};
@@ -7,7 +8,7 @@ use quickcheck::{Arbitrary, Gen};
/// [Section 4.3 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-4.3
///
/// The values correspond to the serialized format.
-#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
+#[derive(Clone, Copy, Debug, Hash)]
pub enum Tag {
/// Reserved Packet tag.
Reserved,
@@ -53,6 +54,30 @@ pub enum Tag {
Private(u8),
}
+impl Eq for Tag {}
+
+impl PartialEq for Tag {
+ fn eq(&self, other: &Tag) -> bool {
+ self.cmp(other) == Ordering::Equal
+ }
+}
+
+impl PartialOrd for Tag
+{
+ fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+ Some(self.cmp(other))
+ }
+}
+
+impl Ord for Tag
+{
+ fn cmp(&self, other: &Self) -> Ordering {
+ let a : u8 = (*self).into();
+ let b : u8 = (*other).into();
+ a.cmp(&b)
+ }
+}
+
impl From<u8> for Tag {
fn from(u: u8) -> Self {
use crate::packet::Tag::*;