Skip to content
Snippets Groups Projects
Commit 917470b8 authored by Michal Kucharczyk's avatar Michal Kucharczyk Committed by Christian Langenbacher
Browse files

HashAndNumber: Ord, Eq, PartialOrd, PartialEq implemented (#7612)

This PR adds implementation of `Ord, Eq, PartialOrd, PartialEq` traits
for [`HashAndNumber`
](https://github.com/paritytech/polkadot-sdk/blob/6e645915

/substrate/primitives/blockchain/src/header_metadata.rs#L149-L154)
struct.

---------

Co-authored-by: default avatarcmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
parent 7b1f00ec
No related merge requests found
title: 'HashAndNumber: Ord, Eq, PartialOrd, PartialEq implemented'
doc:
- audience: Node Dev
description: This PR adds implementation of `Ord, Eq, PartialOrd, PartialEq` traits
for `HashAndNumber` struct.
crates:
- name: sp-blockchain
bump: minor
......@@ -153,6 +153,29 @@ pub struct HashAndNumber<Block: BlockT> {
pub hash: Block::Hash,
}
impl<Block: BlockT> Eq for HashAndNumber<Block> {}
impl<Block: BlockT> PartialEq for HashAndNumber<Block> {
fn eq(&self, other: &Self) -> bool {
self.number.eq(&other.number) && self.hash.eq(&other.hash)
}
}
impl<Block: BlockT> Ord for HashAndNumber<Block> {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
match self.number.cmp(&other.number) {
std::cmp::Ordering::Equal => self.hash.cmp(&other.hash),
result => result,
}
}
}
impl<Block: BlockT> PartialOrd for HashAndNumber<Block> {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(&other))
}
}
/// A tree-route from one block to another in the chain.
///
/// All blocks prior to the pivot in the vector is the reverse-order unique ancestry
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment