@@ -7,19 +7,20 @@ pub const fn pod_get_packed_len<T: Pod>() -> usize {
7
7
std:: mem:: size_of :: < T > ( )
8
8
}
9
9
10
- /// Convert a `Pod` into a slice (zero copy)
10
+ /// Convert a `Pod` into a slice of bytes (zero copy)
11
11
pub fn pod_bytes_of < T : Pod > ( t : & T ) -> & [ u8 ] {
12
12
bytemuck:: bytes_of ( t)
13
13
}
14
14
15
- /// Convert a slice into a `Pod` (zero copy)
15
+ /// Convert a slice of bytes into a `Pod` (zero copy)
16
16
pub fn pod_from_bytes < T : Pod > ( bytes : & [ u8 ] ) -> Result < & T , ProgramError > {
17
17
bytemuck:: try_from_bytes ( bytes) . map_err ( |_| ProgramError :: InvalidArgument )
18
18
}
19
19
20
- /// Maybe convert a slice into a `Pod` (zero copy)
20
+ /// Maybe convert a slice of bytes into a `Pod` (zero copy)
21
21
///
22
- /// Returns `None` if the slice is empty, but `Err` if all other lengths but `get_packed_len()`
22
+ /// Returns `None` if the slice is empty, or else `Err` if input length is not equal to
23
+ /// `pod_get_packed_len::<T>()`.
23
24
/// This function exists primarily because `Option<T>` is not a `Pod`.
24
25
pub fn pod_maybe_from_bytes < T : Pod > ( bytes : & [ u8 ] ) -> Result < Option < & T > , ProgramError > {
25
26
if bytes. is_empty ( ) {
@@ -31,22 +32,22 @@ pub fn pod_maybe_from_bytes<T: Pod>(bytes: &[u8]) -> Result<Option<&T>, ProgramE
31
32
}
32
33
}
33
34
34
- /// Convert a slice into a mutable `Pod` (zero copy)
35
+ /// Convert a slice of bytes into a mutable `Pod` (zero copy)
35
36
pub fn pod_from_bytes_mut < T : Pod > ( bytes : & mut [ u8 ] ) -> Result < & mut T , ProgramError > {
36
37
bytemuck:: try_from_bytes_mut ( bytes) . map_err ( |_| ProgramError :: InvalidArgument )
37
38
}
38
39
39
- /// Convert a slice into a `Pod` slice (zero copy)
40
+ /// Convert a slice of bytes into a `Pod` slice (zero copy)
40
41
pub fn pod_slice_from_bytes < T : Pod > ( bytes : & [ u8 ] ) -> Result < & [ T ] , ProgramError > {
41
42
bytemuck:: try_cast_slice ( bytes) . map_err ( |_| ProgramError :: InvalidArgument )
42
43
}
43
44
44
- /// Convert a slice into a mutable `Pod` slice (zero copy)
45
+ /// Convert a slice of bytes into a mutable `Pod` slice (zero copy)
45
46
pub fn pod_slice_from_bytes_mut < T : Pod > ( bytes : & mut [ u8 ] ) -> Result < & mut [ T ] , ProgramError > {
46
47
bytemuck:: try_cast_slice_mut ( bytes) . map_err ( |_| ProgramError :: InvalidArgument )
47
48
}
48
49
49
- /// Convert a pod slice into its raw bytes
50
+ /// Convert a `Pod` slice into a single slice of bytes
50
51
pub fn pod_slice_to_bytes < T : Pod > ( slice : & [ T ] ) -> & [ u8 ] {
51
52
bytemuck:: cast_slice ( slice)
52
53
}
0 commit comments