Skip to content

Commit 2694a35

Browse files
committed
Requiring for array newtypes to manually derive Copy
1 parent 72ef809 commit 2694a35

File tree

5 files changed

+7
-3
lines changed

5 files changed

+7
-3
lines changed

secp256k1-sys/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ pub type SchnorrNonceFn = Option<unsafe extern "C" fn(
9999

100100
/// Library-internal representation of a Secp256k1 public key
101101
#[repr(C)]
102+
#[derive(Copy)]
102103
pub struct PublicKey([c_uchar; 64]);
103104
impl_array_newtype!(PublicKey, c_uchar, 64);
104105
impl_raw_debug!(PublicKey);
@@ -141,6 +142,7 @@ impl hash::Hash for PublicKey {
141142

142143
/// Library-internal representation of a Secp256k1 signature
143144
#[repr(C)]
145+
#[derive(Copy)]
144146
pub struct Signature([c_uchar; 64]);
145147
impl_array_newtype!(Signature, c_uchar, 64);
146148
impl_raw_debug!(Signature);
@@ -176,6 +178,7 @@ impl Signature {
176178
}
177179

178180
#[repr(C)]
181+
#[derive(Copy)]
179182
pub struct XOnlyPublicKey([c_uchar; 64]);
180183
impl_array_newtype!(XOnlyPublicKey, c_uchar, 64);
181184
impl_raw_debug!(XOnlyPublicKey);

secp256k1-sys/src/macros.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ macro_rules! impl_array_newtype {
6868
pub fn is_empty(&self) -> bool { false }
6969
}
7070

71-
impl Copy for $thing {}
72-
7371
impl Clone for $thing {
7472
#[inline]
7573
fn clone(&self) -> $thing {
@@ -167,7 +165,7 @@ macro_rules! impl_raw_debug {
167165
($thing:ident) => {
168166
impl ::core::fmt::Debug for $thing {
169167
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
170-
for i in self[..].iter().cloned() {
168+
for i in &self[..] {
171169
write!(f, "{:02x}", i)?;
172170
}
173171
Ok(())

secp256k1-sys/src/recovery.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use {Context, Signature, NonceFn, PublicKey};
2020

2121
/// Library-internal representation of a Secp256k1 signature + recovery ID
2222
#[repr(C)]
23+
#[derive(Copy)]
2324
pub struct RecoverableSignature([c_uchar; 65]);
2425
impl_array_newtype!(RecoverableSignature, c_uchar, 65);
2526
impl_raw_debug!(RecoverableSignature);

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ impl<'de> ::serde::Deserialize<'de> for Signature {
458458
}
459459

460460
/// A (hashed) message input to an ECDSA signature
461+
#[derive(Copy)]
461462
pub struct Message([u8; constants::MESSAGE_SIZE]);
462463
impl_array_newtype!(Message, u8, constants::MESSAGE_SIZE);
463464
impl_pretty_debug!(Message);

src/schnorrsig.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use {Message, Signing, Verification};
1616
use SecretKey;
1717

1818
/// Represents a Schnorr signature.
19+
#[derive(Copy)]
1920
pub struct Signature([u8; constants::SCHNORRSIG_SIGNATURE_SIZE]);
2021
impl_array_newtype!(Signature, u8, constants::SCHNORRSIG_SIGNATURE_SIZE);
2122
impl_pretty_debug!(Signature);

0 commit comments

Comments
 (0)