diff options
Diffstat (limited to 'src/util.rs')
-rw-r--r-- | src/util.rs | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/src/util.rs b/src/util.rs index 6b7180a..70e114b 100644 --- a/src/util.rs +++ b/src/util.rs @@ -17,15 +17,12 @@ impl MaybeUninitByteSlice for &[MaybeUninit<u8>] "Invalid item alignment" ); - if size_of::<Item>() == 0 { + let new_len = self.len() / size_of::<Item>(); + + if new_len == 0 { return &[]; } - unsafe { - std::slice::from_raw_parts( - self.as_ptr().cast::<Item>(), - self.len() / size_of::<Item>(), - ) - } + unsafe { std::slice::from_raw_parts(self.as_ptr().cast::<Item>(), new_len) } } } |