Skip to content

Commit 32c81fc

Browse files
committed
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`.
1 parent 24b3ad7 commit 32c81fc

File tree

4 files changed

+3
-13
lines changed

4 files changed

+3
-13
lines changed

src/key.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ use crate::{hashes, ThirtyTwoByteHash};
5656
/// ```
5757
/// [`bincode`]: https://docs.rs/bincode
5858
/// [`cbor`]: https://docs.rs/cbor
59-
#[derive(PartialOrd, Ord, PartialEq, Eq, Hash)]
59+
#[derive(Copy, Clone, PartialOrd, Ord, PartialEq, Eq, Hash)]
6060
pub struct SecretKey([u8; constants::SECRET_KEY_SIZE]);
6161
impl_array_newtype!(SecretKey, u8, constants::SECRET_KEY_SIZE);
6262
impl_display_secret!(SecretKey);

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ impl<T: hashes::sha256t::Tag> ThirtyTwoByteHash for hashes::sha256t::Hash<T> {
233233
}
234234

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

src/macros.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
#[macro_export]
1818
macro_rules! impl_array_newtype {
1919
($thing:ident, $ty:ty, $len:expr) => {
20-
impl Copy for $thing {}
21-
2220
impl AsRef<[$ty; $len]> for $thing {
2321
#[inline]
2422
/// Gets a reference to the underlying array
@@ -28,14 +26,6 @@ macro_rules! impl_array_newtype {
2826
}
2927
}
3028

31-
impl Clone for $thing {
32-
#[inline]
33-
fn clone(&self) -> $thing {
34-
let &$thing(ref dat) = self;
35-
$thing(dat.clone())
36-
}
37-
}
38-
3929
impl<I> core::ops::Index<I> for $thing
4030
where
4131
[$ty]: core::ops::Index<I>,

src/schnorr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::SECP256K1;
1414
use crate::{constants, from_hex, impl_array_newtype, Error, Message, Secp256k1, Signing, Verification};
1515

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

0 commit comments

Comments
 (0)