diff --git a/src/lib.rs b/src/lib.rs index 9b2fc43c..2a6e7289 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,7 +22,7 @@ use unsigned_varint::{decode, encode}; pub use errors::{DecodeError, DecodeOwnedError, EncodeError}; pub use hashes::Hash; -use std::fmt; +use std::{cmp, fmt}; use storage::Storage; // Helper macro for encoding input into output using sha1, sha2, tiny_keccak, or blake2 @@ -246,8 +246,20 @@ impl TryFrom> for Multihash { } } +impl PartialOrd for Multihash { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Ord for Multihash { + fn cmp(&self, other: &Self) -> cmp::Ordering { + self.as_ref().cmp(&other.as_ref()) + } +} + /// Represents a valid multihash. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct MultihashRef<'a> { bytes: &'a [u8], }