Skip to content

Commit a815272

Browse files
committed
secp256k1: Remove custom implementations of Eq, Ord and friends
Now that we have Rust 1.48 as the MSRV we no longer need the custom implementations of `PartialEq`, `Eq`, `PartialOrd`, `Ord`, and `Hash`. We can just let users of the `impl_array_newtype` macro derive these traits if they want them. Remove the custom implementations and add derives to our two users of the macro.
1 parent ee83c3a commit a815272

File tree

4 files changed

+4
-27
lines changed

4 files changed

+4
-27
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Unreleased
22

33
* Bump MSRV to 1.48
4+
* Remove implementations of `PartialEq`, `Eq`, `PartialOrd`, `Ord`, and `Hash` from the
5+
`impl_array_newtype` macro. Users will now need to derive these traits if they are wanted.
46

57
# 0.27.0 - 2023-03-15
68

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ impl<T: hashes::sha256t::Tag> ThirtyTwoByteHash for hashes::sha256t::Hash<T> {
232232
}
233233

234234
/// A (hashed) message input to an ECDSA signature.
235-
#[derive(Copy, Clone)]
235+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
236236
pub struct Message([u8; constants::MESSAGE_SIZE]);
237237
impl_array_newtype!(Message, u8, constants::MESSAGE_SIZE);
238238
impl_pretty_debug!(Message);

src/macros.rs

-25
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,6 @@
1717
#[macro_export]
1818
macro_rules! impl_array_newtype {
1919
($thing:ident, $ty:ty, $len:expr) => {
20-
// We cannot derive these traits because Rust 1.41.1 requires `std::array::LengthAtMost32`.
21-
22-
impl PartialEq for $thing {
23-
#[inline]
24-
fn eq(&self, other: &$thing) -> bool { &self[..] == &other[..] }
25-
}
26-
27-
impl Eq for $thing {}
28-
29-
impl core::hash::Hash for $thing {
30-
fn hash<H: core::hash::Hasher>(&self, state: &mut H) { (&self[..]).hash(state) }
31-
}
32-
33-
impl PartialOrd for $thing {
34-
#[inline]
35-
fn partial_cmp(&self, other: &$thing) -> Option<core::cmp::Ordering> {
36-
self[..].partial_cmp(&other[..])
37-
}
38-
}
39-
40-
impl Ord for $thing {
41-
#[inline]
42-
fn cmp(&self, other: &$thing) -> core::cmp::Ordering { self[..].cmp(&other[..]) }
43-
}
44-
4520
impl AsRef<[$ty; $len]> for $thing {
4621
#[inline]
4722
/// Gets a reference to the underlying array

src/schnorr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{
1515
};
1616

1717
/// Represents a schnorr signature.
18-
#[derive(Copy, Clone)]
18+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1919
pub struct Signature([u8; constants::SCHNORR_SIGNATURE_SIZE]);
2020
impl_array_newtype!(Signature, u8, constants::SCHNORR_SIGNATURE_SIZE);
2121
impl_pretty_debug!(Signature);

0 commit comments

Comments
 (0)