diff --git a/Cargo.toml b/Cargo.toml index 57971fe3..349e530e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bitcoin" -version = "0.5.0" +version = "0.5.1" authors = ["Andrew Poelstra "] license = "CC0-1.0" homepage = "https://github.com/apoelstra/rust-bitcoin/" diff --git a/src/blockdata/transaction.rs b/src/blockdata/transaction.rs index d39df3db..ffdfb076 100644 --- a/src/blockdata/transaction.rs +++ b/src/blockdata/transaction.rs @@ -33,7 +33,7 @@ use network::encodable::ConsensusEncodable; use network::serialize::BitcoinHash; /// 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 { /// The referenced transaction's txid pub txid: Sha256dHash, diff --git a/src/internal_macros.rs b/src/internal_macros.rs index 723a0d96..b0280896 100644 --- a/src/internal_macros.rs +++ b/src/internal_macros.rs @@ -115,6 +115,28 @@ macro_rules! impl_array_newtype { 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 { #[inline] fn clone(&self) -> $thing { diff --git a/src/util/uint.rs b/src/util/uint.rs index 3d63ca24..cfddaa9f 100644 --- a/src/util/uint.rs +++ b/src/util/uint.rs @@ -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 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let &$name(ref data) = self;