Skip to content

Commit ad41e74

Browse files
committed
list-view: drop spl-pod dependency
1 parent 192cf30 commit ad41e74

7 files changed

Lines changed: 34 additions & 24 deletions

File tree

Cargo.lock

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

list-view/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ num-derive = "0.4.2"
1313
num_enum = "0.7.5"
1414
num-traits = "0.2.19"
1515
solana-program-error = "3.0.0"
16-
spl-pod = { version = "0.7.2", path = "../pod", features = ["bytemuck"] }
16+
solana-zero-copy = { version = "1.0.0", features = ["bytemuck"] }
1717
thiserror = "2.0.18"
1818

1919
[dev-dependencies]

list-view/src/list_trait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use {
1010
pub trait List: Deref<Target = [Self::Item]> {
1111
/// The type of the items stored in the list.
1212
type Item: Pod;
13-
/// Length prefix type used (`PodU16`, `PodU32`, ).
13+
/// Length prefix type used (`U16`, `U32`, ...).
1414
type Length: PodLength;
1515

1616
/// Returns the total number of items that can be stored in the list.

list-view/src/list_view.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,14 @@ use {
55
error::ListViewError, list_view_mut::ListViewMut, list_view_read_only::ListViewReadOnly,
66
pod_length::PodLength,
77
},
8-
bytemuck::Pod,
8+
bytemuck::{try_cast_slice, try_cast_slice_mut, try_from_bytes, try_from_bytes_mut, Pod},
99
core::{
1010
marker::PhantomData,
1111
mem::{align_of, size_of},
1212
ops::Range,
1313
},
1414
solana_program_error::ProgramError,
15-
spl_pod::{
16-
bytemuck::{
17-
pod_from_bytes, pod_from_bytes_mut, pod_slice_from_bytes, pod_slice_from_bytes_mut,
18-
},
19-
primitives::PodU32,
20-
},
15+
solana_zero_copy::unaligned::U32,
2116
};
2217

2318
/// An API for interpreting a raw buffer (`&[u8]`) as a variable-length collection of Pod elements.
@@ -36,13 +31,13 @@ use {
3631
/// The structure assumes the underlying byte buffer is formatted as follows:
3732
/// 1. **Length**: A length field of type `L` at the beginning of the buffer,
3833
/// indicating the number of currently active elements in the collection.
39-
/// Defaults to `PodU32`. The implementation uses padding to ensure that the
34+
/// Defaults to `U32`. The implementation uses padding to ensure that the
4035
/// data is correctly aligned for any `Pod` type.
4136
/// 2. **Padding**: Optional padding bytes to ensure proper alignment of the data.
4237
/// 3. **Data**: The remaining part of the buffer, which is treated as a slice
4338
/// of `T` elements. The capacity of the collection is the number of `T`
4439
/// elements that can fit into this data portion.
45-
pub struct ListView<T: Pod, L: PodLength = PodU32>(PhantomData<(T, L)>);
40+
pub struct ListView<T: Pod, L: PodLength = U32>(PhantomData<(T, L)>);
4641

4742
struct Layout {
4843
length_range: Range<usize>,
@@ -75,8 +70,9 @@ impl<T: Pod, L: PodLength> ListView<T, L> {
7570
let len_bytes = &buf[layout.length_range];
7671
let data_bytes = &buf[layout.data_range];
7772

78-
let length = pod_from_bytes::<L>(len_bytes)?;
79-
let data = pod_slice_from_bytes::<T>(data_bytes)?;
73+
let length = try_from_bytes::<L>(len_bytes).map_err(|_| ProgramError::InvalidArgument)?;
74+
let data =
75+
try_cast_slice::<u8, T>(data_bytes).map_err(|_| ProgramError::InvalidArgument)?;
8076
let capacity = data.len();
8177

8278
if (*length).into() > capacity {
@@ -121,8 +117,10 @@ impl<T: Pod, L: PodLength> ListView<T, L> {
121117
let len_bytes = &mut header_bytes[layout.length_range];
122118

123119
// Cast the bytes to typed data
124-
let length = pod_from_bytes_mut::<L>(len_bytes)?;
125-
let data = pod_slice_from_bytes_mut::<T>(data_bytes)?;
120+
let length =
121+
try_from_bytes_mut::<L>(len_bytes).map_err(|_| ProgramError::InvalidArgument)?;
122+
let data =
123+
try_cast_slice_mut::<u8, T>(data_bytes).map_err(|_| ProgramError::InvalidArgument)?;
126124
let capacity = data.len();
127125

128126
Ok(ListViewMut {
@@ -188,7 +186,9 @@ mod tests {
188186
super::*,
189187
crate::List,
190188
bytemuck_derive::{Pod as DerivePod, Zeroable},
191-
spl_pod::primitives::{PodU128, PodU16, PodU32, PodU64},
189+
solana_zero_copy::unaligned::{
190+
U128 as PodU128, U16 as PodU16, U32 as PodU32, U64 as PodU64,
191+
},
192192
};
193193

194194
#[test]

list-view/src/list_view_mut.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ use {
55
bytemuck::Pod,
66
core::ops::{Deref, DerefMut},
77
solana_program_error::ProgramError,
8-
spl_pod::primitives::PodU32,
8+
solana_zero_copy::unaligned::U32,
99
};
1010

1111
#[derive(Debug)]
12-
pub struct ListViewMut<'data, T: Pod, L: PodLength = PodU32> {
12+
pub struct ListViewMut<'data, T: Pod, L: PodLength = U32> {
1313
pub(crate) length: &'data mut L,
1414
pub(crate) data: &'data mut [T],
1515
pub(crate) capacity: usize,
@@ -83,7 +83,7 @@ mod tests {
8383
super::*,
8484
crate::{List, ListView},
8585
bytemuck_derive::{Pod, Zeroable},
86-
spl_pod::primitives::{PodU16, PodU32, PodU64},
86+
solana_zero_copy::unaligned::{U16 as PodU16, U32 as PodU32, U64 as PodU64},
8787
};
8888

8989
#[repr(C)]

list-view/src/list_view_read_only.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ use {
44
crate::{list_trait::List, pod_length::PodLength},
55
bytemuck::Pod,
66
core::ops::Deref,
7-
spl_pod::primitives::PodU32,
7+
solana_zero_copy::unaligned::U32,
88
};
99

1010
#[derive(Debug)]
11-
pub struct ListViewReadOnly<'data, T: Pod, L: PodLength = PodU32> {
11+
pub struct ListViewReadOnly<'data, T: Pod, L: PodLength = U32> {
1212
pub(crate) length: &'data L,
1313
pub(crate) data: &'data [T],
1414
pub(crate) capacity: usize,
@@ -39,7 +39,7 @@ mod tests {
3939
crate::ListView,
4040
bytemuck_derive::{Pod as DerivePod, Zeroable},
4141
core::mem::size_of,
42-
spl_pod::primitives::{PodU32, PodU64},
42+
solana_zero_copy::unaligned::{U32 as PodU32, U64 as PodU64},
4343
};
4444

4545
#[repr(C, align(16))]

tlv-account-resolution/src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl ExtraAccountMetaList {
191191
tlv_state: &'a TlvStateBorrowed,
192192
) -> Result<ListViewReadOnly<'a, ExtraAccountMeta, PodU32>, ProgramError> {
193193
let bytes = tlv_state.get_first_bytes::<T>()?;
194-
ListView::<ExtraAccountMeta>::unpack(bytes)
194+
ListView::<ExtraAccountMeta, PodU32>::unpack(bytes)
195195
}
196196

197197
/// Get the byte size required to hold `num_items` items

0 commit comments

Comments
 (0)