Derive Pod/Zeroable for Pubkey (backport #20493) (#20496)

* Derive Pod/Zeroable for Pubkey

(cherry picked from commit f966859829)

# Conflicts:
#	Cargo.lock
#	programs/bpf/Cargo.lock
#	sdk/program/Cargo.toml

* rebase

Co-authored-by: Michael Vines <mvines@gmail.com>
This commit is contained in:
mergify[bot]
2021-10-07 07:59:17 +00:00
committed by GitHub
parent 2d930052dc
commit 4892eb4e1a
4 changed files with 63 additions and 16 deletions

21
Cargo.lock generated
View File

@ -468,6 +468,26 @@ version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0017894339f586ccb943b01b9555de56770c11cda818e7e3d8bd93f4ed7f46e"
[[package]]
name = "bytemuck"
version = "1.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72957246c41db82b8ef88a5486143830adeb8227ef9837740bdec67724cf2c5b"
dependencies = [
"bytemuck_derive",
]
[[package]]
name = "bytemuck_derive"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e215f8c2f9f79cb53c8335e687ffd07d5bfcb6fe5fc80723762d0be46e7cc54"
dependencies = [
"proc-macro2 1.0.24",
"quote 1.0.9",
"syn 1.0.60",
]
[[package]]
name = "byteorder"
version = "1.3.4"
@ -5101,6 +5121,7 @@ dependencies = [
"borsh-derive",
"bs58",
"bv",
"bytemuck",
"curve25519-dalek 2.1.0",
"hex",
"itertools 0.9.0",

View File

@ -294,6 +294,26 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7"
[[package]]
name = "bytemuck"
version = "1.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72957246c41db82b8ef88a5486143830adeb8227ef9837740bdec67724cf2c5b"
dependencies = [
"bytemuck_derive",
]
[[package]]
name = "bytemuck_derive"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e215f8c2f9f79cb53c8335e687ffd07d5bfcb6fe5fc80723762d0be46e7cc54"
dependencies = [
"proc-macro2 1.0.24",
"quote 1.0.6",
"syn 1.0.67",
]
[[package]]
name = "byteorder"
version = "0.5.3"
@ -3283,6 +3303,7 @@ dependencies = [
"borsh-derive",
"bs58",
"bv",
"bytemuck",
"curve25519-dalek 2.1.0",
"hex",
"itertools 0.9.0",

View File

@ -15,6 +15,7 @@ bincode = "1.3.1"
borsh = "0.9.0"
borsh-derive = "0.9.0"
bs58 = "0.3.1"
bytemuck = { version = "1.7.2", features = ["derive"] }
bv = { version = "0.11.1", features = ["serde"] }
hex = "0.4.2"
itertools = "0.9.0"

View File

@ -1,14 +1,16 @@
#![allow(clippy::integer_arithmetic)]
use crate::{decode_error::DecodeError, hash::hashv};
use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use num_derive::{FromPrimitive, ToPrimitive};
use std::{
convert::{Infallible, TryFrom},
fmt, mem,
str::FromStr,
use {
crate::{decode_error::DecodeError, hash::hashv},
borsh::{BorshDeserialize, BorshSchema, BorshSerialize},
bytemuck::{Pod, Zeroable},
num_derive::{FromPrimitive, ToPrimitive},
std::{
convert::{Infallible, TryFrom},
fmt, mem,
str::FromStr,
},
thiserror::Error,
};
use thiserror::Error;
/// Number of bytes in a pubkey
pub const PUBKEY_BYTES: usize = 32;
@ -48,20 +50,22 @@ impl From<u64> for PubkeyError {
#[repr(transparent)]
#[derive(
Serialize,
Deserialize,
BorshSerialize,
AbiExample,
BorshDeserialize,
BorshSchema,
BorshSerialize,
Clone,
Copy,
Default,
Deserialize,
Eq,
PartialEq,
Ord,
PartialOrd,
Hash,
AbiExample,
Ord,
PartialEq,
PartialOrd,
Pod,
Serialize,
Zeroable,
)]
pub struct Pubkey([u8; 32]);