Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 3ce05a3

Browse files
author
Tyera
authored
spl-pod: make code docs more explicit (#5178)
Make code docs more explicit
1 parent c79c727 commit 3ce05a3

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

libraries/pod/src/bytemuck.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,20 @@ pub const fn pod_get_packed_len<T: Pod>() -> usize {
77
std::mem::size_of::<T>()
88
}
99

10-
/// Convert a `Pod` into a slice (zero copy)
10+
/// Convert a `Pod` into a slice of bytes (zero copy)
1111
pub fn pod_bytes_of<T: Pod>(t: &T) -> &[u8] {
1212
bytemuck::bytes_of(t)
1313
}
1414

15-
/// Convert a slice into a `Pod` (zero copy)
15+
/// Convert a slice of bytes into a `Pod` (zero copy)
1616
pub fn pod_from_bytes<T: Pod>(bytes: &[u8]) -> Result<&T, ProgramError> {
1717
bytemuck::try_from_bytes(bytes).map_err(|_| ProgramError::InvalidArgument)
1818
}
1919

20-
/// Maybe convert a slice into a `Pod` (zero copy)
20+
/// Maybe convert a slice of bytes into a `Pod` (zero copy)
2121
///
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>()`.
2324
/// This function exists primarily because `Option<T>` is not a `Pod`.
2425
pub fn pod_maybe_from_bytes<T: Pod>(bytes: &[u8]) -> Result<Option<&T>, ProgramError> {
2526
if bytes.is_empty() {
@@ -31,22 +32,22 @@ pub fn pod_maybe_from_bytes<T: Pod>(bytes: &[u8]) -> Result<Option<&T>, ProgramE
3132
}
3233
}
3334

34-
/// Convert a slice into a mutable `Pod` (zero copy)
35+
/// Convert a slice of bytes into a mutable `Pod` (zero copy)
3536
pub fn pod_from_bytes_mut<T: Pod>(bytes: &mut [u8]) -> Result<&mut T, ProgramError> {
3637
bytemuck::try_from_bytes_mut(bytes).map_err(|_| ProgramError::InvalidArgument)
3738
}
3839

39-
/// Convert a slice into a `Pod` slice (zero copy)
40+
/// Convert a slice of bytes into a `Pod` slice (zero copy)
4041
pub fn pod_slice_from_bytes<T: Pod>(bytes: &[u8]) -> Result<&[T], ProgramError> {
4142
bytemuck::try_cast_slice(bytes).map_err(|_| ProgramError::InvalidArgument)
4243
}
4344

44-
/// Convert a slice into a mutable `Pod` slice (zero copy)
45+
/// Convert a slice of bytes into a mutable `Pod` slice (zero copy)
4546
pub fn pod_slice_from_bytes_mut<T: Pod>(bytes: &mut [u8]) -> Result<&mut [T], ProgramError> {
4647
bytemuck::try_cast_slice_mut(bytes).map_err(|_| ProgramError::InvalidArgument)
4748
}
4849

49-
/// Convert a pod slice into its raw bytes
50+
/// Convert a `Pod` slice into a single slice of bytes
5051
pub fn pod_slice_to_bytes<T: Pod>(slice: &[T]) -> &[u8] {
5152
bytemuck::cast_slice(slice)
5253
}

0 commit comments

Comments
 (0)