Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions pod/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@ edition = "2021"

[features]
bytemuck = ["dep:bytemuck", "dep:bytemuck_derive", "solana-address/bytemuck"]
serde = ["dep:serde", "solana-address/decode"]
serde = ["dep:serde", "dep:serde_derive", "solana-address/decode"]
borsh = ["dep:borsh", "solana-address/borsh"]
wincode = ["dep:wincode"]
wincode = ["dep:wincode", "dep:wincode-derive"]

[dependencies]
borsh = { version = "1.5.7", features = ["derive", "unstable__schema"], optional = true }
borsh = { version = "1.5.7", default-features = false, features = ["derive", "unstable__schema"], optional = true }
bytemuck = { version = "1.23.2", optional = true }
bytemuck_derive = { version = "1.10.1", optional = true }
serde = { version = "1.0.228", optional = true, features = ["derive"] }
serde = { version = "1.0.228", default-features = false, optional = true, features = ["alloc"] }
serde_derive = { version = "1.0.228", optional = true }
solana-address = { version = "2.2.0", features = ["copy"] }
solana-program-error = "3.0.0"
solana-program-option = "3.0.0"
wincode = { version = "0.4.4", features = ["derive"], optional = true }
wincode = { version = "0.4.4", default-features = false, optional = true }
wincode-derive = { version = "0.4.2", optional = true }

[dev-dependencies]
base64 = { version = "0.22.1" }
Expand Down
5 changes: 5 additions & 0 deletions pod/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#![no_std]

//! Crate containing `Pod` types and `bytemuck` utilities used in SPL

#[cfg(any(feature = "borsh", feature = "serde", test))]
extern crate alloc;

#[cfg(feature = "bytemuck")]
pub mod bytemuck;
pub mod option;
Expand Down
2 changes: 1 addition & 1 deletion pod/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ impl Nullable for Address {

#[cfg(test)]
mod tests {
use super::*;
#[cfg(feature = "bytemuck")]
use crate::bytemuck::pod_slice_from_bytes;
use {super::*, alloc::vec::Vec};
const ID: Address = Address::from_str_const("TestSysvar111111111111111111111111111111111");

#[cfg(feature = "bytemuck")]
Expand Down
2 changes: 2 additions & 0 deletions pod/src/optional_keys.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//! Optional addresses that can be used a `Pod`s
#[cfg(any(feature = "borsh", feature = "serde"))]
use alloc::string::ToString;
#[cfg(feature = "borsh")]
use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
#[cfg(feature = "bytemuck")]
Expand Down
22 changes: 13 additions & 9 deletions pod/src/primitives.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
//! primitive types that can be used in `Pod`s
#[cfg(feature = "borsh")]
use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
Comment on lines -2 to -3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, totally missed that 😅

#[cfg(feature = "bytemuck")]
use bytemuck_derive::{Pod, Zeroable};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use serde_derive::{Deserialize, Serialize};
#[cfg(feature = "wincode")]
use wincode::{SchemaRead, SchemaWrite};
use wincode_derive::{SchemaRead, SchemaWrite};
#[cfg(feature = "borsh")]
use {
alloc::string::ToString,
borsh::{BorshDeserialize, BorshSchema, BorshSerialize},
};

/// The standard `bool` is not a `Pod`, define a replacement that is
#[cfg_attr(feature = "wincode", derive(SchemaRead, SchemaWrite))]
Expand Down Expand Up @@ -245,9 +248,6 @@ mod tests {
#[test]
fn test_pod_i16_serde() {
let pod_i16: PodI16 = i16::MAX.into();

println!("pod_i16 {:?}", pod_i16);

let serialized = serde_json::to_string(&pod_i16).unwrap();
assert_eq!(&serialized, "32767");

Expand Down Expand Up @@ -371,8 +371,12 @@ mod tests {
>(
pod: T,
) {
let bytes = wincode::serialize(&pod).unwrap();
let deserialized: T = wincode::deserialize(&bytes).unwrap();
let size = wincode::serialized_size(&pod).unwrap() as usize;
let mut bytes = [0u8; 32];
assert!(size <= bytes.len());
wincode::serialize_into(&mut bytes[..size], &pod).unwrap();

let deserialized: T = wincode::deserialize(&bytes[..size]).unwrap();
assert_eq!(pod, deserialized);
}
}
Expand Down
Loading