summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@pep.foundation>2019-09-02 12:11:39 +0200
committerNeal H. Walfield <neal@pep.foundation>2019-09-02 13:32:03 +0200
commit9ecdf6c36293a3990016ee18b45a5a19a6c220d2 (patch)
tree4dcc7a80690b8e1cd65b5ba7ddf4ccb8c8894ed2
parent3c1325b8fad753b2006c215535c6d0b162c62166 (diff)
openpgp: Implement Ord for Unknown
- Sort by tag, then the body (lexographically).
-rw-r--r--openpgp/src/packet/unknown.rs25
1 files changed, 23 insertions, 2 deletions
diff --git a/openpgp/src/packet/unknown.rs b/openpgp/src/packet/unknown.rs
index 44e1b334..07cd5e0e 100644
--- a/openpgp/src/packet/unknown.rs
+++ b/openpgp/src/packet/unknown.rs
@@ -1,5 +1,7 @@
-use failure;
use std::hash::{Hash, Hasher};
+use std::cmp::Ordering;
+
+use failure;
use crate::packet::Tag;
use crate::packet;
@@ -25,9 +27,28 @@ impl Eq for Unknown {}
impl PartialEq for Unknown {
fn eq(&self, other: &Unknown) -> bool {
+ self.cmp(other) == Ordering::Equal
+ }
+}
+
+impl PartialOrd for Unknown
+{
+ fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+ Some(self.cmp(other))
+ }
+}
+
+impl Ord for Unknown
+{
+ fn cmp(&self, other: &Unknown) -> Ordering {
+ // An unknown packet cannot have children.
assert!(self.common.children.is_none());
assert!(other.common.children.is_none());
- self.common.body == other.common.body && self.tag == other.tag
+
+ match self.tag.cmp(&other.tag) {
+ Ordering::Equal => self.common.body().cmp(&other.common.body()),
+ o => o,
+ }
}
}