diff options
author | Neal H. Walfield <neal@pep.foundation> | 2019-09-02 12:17:35 +0200 |
---|---|---|
committer | Neal H. Walfield <neal@pep.foundation> | 2019-09-02 13:32:04 +0200 |
commit | af8e974dd2d9f3e210a4fff395847dc50cdfaf9c (patch) | |
tree | dfa76a2fe55664206c3f6d6da85012f97b6cc689 | |
parent | 9ecdf6c36293a3990016ee18b45a5a19a6c220d2 (diff) |
openpgp: Implement Ord for UserAttribute
- Also, ignore the common bits when comparing two UserAttributes for
equality; just consider their values.
-rw-r--r-- | openpgp/src/packet/user_attribute.rs | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/openpgp/src/packet/user_attribute.rs b/openpgp/src/packet/user_attribute.rs index 9e1f309a..8c3bdebb 100644 --- a/openpgp/src/packet/user_attribute.rs +++ b/openpgp/src/packet/user_attribute.rs @@ -5,6 +5,8 @@ //! [Section 5.12 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-5.12 use std::fmt; +use std::cmp::Ordering; + use quickcheck::{Arbitrary, Gen}; use rand::Rng; @@ -25,7 +27,7 @@ use crate::serialize::SerializeInto; /// See [Section 5.12 of RFC 4880] for details. /// /// [Section 5.12 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-5.12 -#[derive(PartialEq, Eq, Hash, Clone)] +#[derive(Hash, Clone)] pub struct UserAttribute { /// CTB packet header fields. pub(crate) common: packet::Common, @@ -51,6 +53,27 @@ impl fmt::Debug for UserAttribute { } } +impl PartialEq for UserAttribute { + fn eq(&self, other: &UserAttribute) -> bool { + self.value == other.value + } +} + +impl Eq for UserAttribute { +} + +impl PartialOrd for UserAttribute { + fn partial_cmp(&self, other: &Self) -> Option<Ordering> { + Some(self.cmp(other)) + } +} + +impl Ord for UserAttribute { + fn cmp(&self, other: &Self) -> Ordering { + self.value.cmp(&other.value) + } +} + impl UserAttribute { /// Returns a new `UserAttribute` packet. /// |