Add a bunch of Ord/PartialOrd impls for stuff
This commit is contained in:
parent
e05e6d2215
commit
16f5878a03
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "bitcoin"
|
name = "bitcoin"
|
||||||
version = "0.5.0"
|
version = "0.5.1"
|
||||||
authors = ["Andrew Poelstra <apoelstra@wpsoftware.net>"]
|
authors = ["Andrew Poelstra <apoelstra@wpsoftware.net>"]
|
||||||
license = "CC0-1.0"
|
license = "CC0-1.0"
|
||||||
homepage = "https://github.com/apoelstra/rust-bitcoin/"
|
homepage = "https://github.com/apoelstra/rust-bitcoin/"
|
||||||
|
|
|
@ -33,7 +33,7 @@ use network::encodable::ConsensusEncodable;
|
||||||
use network::serialize::BitcoinHash;
|
use network::serialize::BitcoinHash;
|
||||||
|
|
||||||
/// A reference to a transaction output
|
/// A reference to a transaction output
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
|
||||||
pub struct TxOutRef {
|
pub struct TxOutRef {
|
||||||
/// The referenced transaction's txid
|
/// The referenced transaction's txid
|
||||||
pub txid: Sha256dHash,
|
pub txid: Sha256dHash,
|
||||||
|
|
|
@ -115,6 +115,28 @@ macro_rules! impl_array_newtype {
|
||||||
|
|
||||||
impl Eq for $thing {}
|
impl Eq for $thing {}
|
||||||
|
|
||||||
|
impl PartialOrd for $thing {
|
||||||
|
#[inline]
|
||||||
|
fn partial_cmp(&self, other: &$thing) -> Option<::std::cmp::Ordering> {
|
||||||
|
Some(self.cmp(&other))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Ord for $thing {
|
||||||
|
#[inline]
|
||||||
|
fn cmp(&self, other: &$thing) -> ::std::cmp::Ordering {
|
||||||
|
// manually implement comparison to get little-endian ordering
|
||||||
|
// (we need this for our numeric types; non-numeric ones shouldn't
|
||||||
|
// be ordered anyway except to put them in BTrees or whatever, and
|
||||||
|
// they don't care how we order as long as we're consisistent).
|
||||||
|
for i in 0..$len {
|
||||||
|
if self[$len - 1 - i] < other[$len - 1 - i] { return ::std::cmp::Ordering::Less; }
|
||||||
|
if self[$len - 1 - i] > other[$len - 1 - i] { return ::std::cmp::Ordering::Greater; }
|
||||||
|
}
|
||||||
|
::std::cmp::Ordering::Equal
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Clone for $thing {
|
impl Clone for $thing {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn clone(&self) -> $thing {
|
fn clone(&self) -> $thing {
|
||||||
|
|
|
@ -307,24 +307,6 @@ macro_rules! construct_uint {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ::std::cmp::Ord for $name {
|
|
||||||
fn cmp(&self, other: &$name) -> ::std::cmp::Ordering {
|
|
||||||
let &$name(ref me) = self;
|
|
||||||
let &$name(ref you) = other;
|
|
||||||
for i in 0..$n_words {
|
|
||||||
if me[$n_words - 1 - i] < you[$n_words - 1 - i] { return ::std::cmp::Ordering::Less; }
|
|
||||||
if me[$n_words - 1 - i] > you[$n_words - 1 - i] { return ::std::cmp::Ordering::Greater; }
|
|
||||||
}
|
|
||||||
::std::cmp::Ordering::Equal
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ::std::cmp::PartialOrd for $name {
|
|
||||||
fn partial_cmp(&self, other: &$name) -> Option<::std::cmp::Ordering> {
|
|
||||||
Some(self.cmp(other))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for $name {
|
impl fmt::Debug for $name {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
let &$name(ref data) = self;
|
let &$name(ref data) = self;
|
||||||
|
|
Loading…
Reference in New Issue