From 32c81fc64414cd2a9830b3b1d8fe92b5accf60d3 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 17 Nov 2022 16:08:55 +1100 Subject: [PATCH] secp256k1: Derive Copy and Clone 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`. --- src/key.rs | 2 +- src/lib.rs | 2 +- src/macros.rs | 10 ---------- src/schnorr.rs | 2 +- 4 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/key.rs b/src/key.rs index 9cbd44d28..e739c964e 100644 --- a/src/key.rs +++ b/src/key.rs @@ -56,7 +56,7 @@ use crate::{hashes, ThirtyTwoByteHash}; /// ``` /// [`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); diff --git a/src/lib.rs b/src/lib.rs index a098ea498..d6b5a724f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -233,7 +233,7 @@ impl ThirtyTwoByteHash for hashes::sha256t::Hash { } /// 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); diff --git a/src/macros.rs b/src/macros.rs index 392291f2f..4ac30b51f 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -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 @@ -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 core::ops::Index for $thing where [$ty]: core::ops::Index, diff --git a/src/schnorr.rs b/src/schnorr.rs index 36cfe6093..1a9c4bc14 100644 --- a/src/schnorr.rs +++ b/src/schnorr.rs @@ -14,7 +14,7 @@ use crate::SECP256K1; use crate::{constants, from_hex, impl_array_newtype, Error, Message, Secp256k1, Signing, Verification}; /// 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);