Implement `Hash` for all array newtypes
* implements `Hash` as part of the newtype macro * removes type-specific implementations
This commit is contained in:
parent
24a9c9c765
commit
75b49efb3d
|
@ -36,7 +36,7 @@ pub mod types;
|
|||
#[cfg(feature = "recovery")]
|
||||
pub mod recovery;
|
||||
|
||||
use core::{hash, slice, ptr};
|
||||
use core::{slice, ptr};
|
||||
use types::*;
|
||||
|
||||
/// Flag for context to enable no precomputation
|
||||
|
@ -133,12 +133,6 @@ impl PublicKey {
|
|||
}
|
||||
}
|
||||
|
||||
impl hash::Hash for PublicKey {
|
||||
fn hash<H: hash::Hasher>(&self, state: &mut H) {
|
||||
state.write(&self.0)
|
||||
}
|
||||
}
|
||||
|
||||
/// Library-internal representation of a Secp256k1 signature
|
||||
#[repr(C)]
|
||||
pub struct Signature([c_uchar; 64]);
|
||||
|
@ -210,12 +204,6 @@ impl XOnlyPublicKey {
|
|||
}
|
||||
}
|
||||
|
||||
impl hash::Hash for XOnlyPublicKey {
|
||||
fn hash<H: hash::Hasher>(&self, state: &mut H) {
|
||||
state.write(&self.0)
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct KeyPair([c_uchar; 96]);
|
||||
impl_array_newtype!(KeyPair, c_uchar, 96);
|
||||
|
@ -251,12 +239,6 @@ impl KeyPair {
|
|||
}
|
||||
}
|
||||
|
||||
impl hash::Hash for KeyPair {
|
||||
fn hash<H: hash::Hasher>(&self, state: &mut H) {
|
||||
state.write(&self.0)
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
/// Default ECDH hash function
|
||||
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_4_1_ecdh_hash_function_default")]
|
||||
|
|
|
@ -61,6 +61,12 @@ macro_rules! impl_array_newtype {
|
|||
|
||||
impl Eq for $thing {}
|
||||
|
||||
impl ::core::hash::Hash for $thing {
|
||||
fn hash<H: ::core::hash::Hasher>(&self, state: &mut H) {
|
||||
(&self[..]).hash(state)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for $thing {
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &$thing) -> Option<::core::cmp::Ordering> {
|
||||
|
|
Loading…
Reference in New Issue