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
4742struct 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]
0 commit comments