Skip to content

Commit

Permalink
secp256k1: Derive Copy and Clone
Browse files Browse the repository at this point in the history
Now that we derive a bunch of traits for the `secp256k1` types that use
`impl_array_newtype` it makes sense to derive `Copy` and `Clone` as
well. This makes the code less surprising because all the impls come
from the same place (the derive attribute).

Note, in `secp256k1-sys` we leave the `Copy` and `Clone` impls in the
macro because there is enough clutter already on the struct definitions
with the fuzzing `cfg_attr`.
  • Loading branch information
tcharding committed Nov 17, 2022
1 parent 3430d40 commit d9447a3
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/key.rs
Expand Up @@ -59,7 +59,7 @@ use crate::Scalar;
/// ```
/// [`bincode`]: https://docs.rs/bincode
/// [`cbor`]: https://docs.rs/cbor
#[derive(PartialOrd, Ord, PartialEq, Eq, Hash)]
#[derive(Copy, Clone, PartialOrd, Ord, PartialEq, Eq, Hash)]
pub struct SecretKey([u8; constants::SECRET_KEY_SIZE]);
impl_array_newtype!(SecretKey, u8, constants::SECRET_KEY_SIZE);
impl_display_secret!(SecretKey);
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Expand Up @@ -241,7 +241,7 @@ impl<T: hashes::sha256t::Tag> ThirtyTwoByteHash for hashes::sha256t::Hash<T> {
}

/// A (hashed) message input to an ECDSA signature.
#[derive(PartialOrd, Ord, PartialEq, Eq, Hash)]
#[derive(Copy, Clone, PartialOrd, Ord, PartialEq, Eq, Hash)]
pub struct Message([u8; constants::MESSAGE_SIZE]);
impl_array_newtype!(Message, u8, constants::MESSAGE_SIZE);
impl_pretty_debug!(Message);
Expand Down
10 changes: 0 additions & 10 deletions src/macros.rs
Expand Up @@ -17,8 +17,6 @@
#[macro_export]
macro_rules! impl_array_newtype {
($thing:ident, $ty:ty, $len:expr) => {
impl Copy for $thing {}

impl AsRef<[$ty; $len]> for $thing {
#[inline]
/// Gets a reference to the underlying array
Expand All @@ -28,14 +26,6 @@ macro_rules! impl_array_newtype {
}
}

impl Clone for $thing {
#[inline]
fn clone(&self) -> $thing {
let &$thing(ref dat) = self;
$thing(dat.clone())
}
}

impl<I> core::ops::Index<I> for $thing
where
[$ty]: core::ops::Index<I>,
Expand Down
2 changes: 1 addition & 1 deletion src/schnorr.rs
Expand Up @@ -15,7 +15,7 @@ use crate::ffi::{self, CPtr};
use crate::SECP256K1;

/// Represents a Schnorr signature.
#[derive(PartialOrd, Ord, PartialEq, Eq, Hash)]
#[derive(Copy, Clone, PartialOrd, Ord, PartialEq, Eq, Hash)]
pub struct Signature([u8; constants::SCHNORR_SIGNATURE_SIZE]);
impl_array_newtype!(Signature, u8, constants::SCHNORR_SIGNATURE_SIZE);
impl_pretty_debug!(Signature);
Expand Down

0 comments on commit d9447a3

Please sign in to comment.