diff options
author | HampusM <hampus@hampusmat.com> | 2025-03-27 21:34:39 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2025-03-28 11:52:48 +0100 |
commit | 714c62e9833f0ebb18d838dd44d6d8ec8d01717f (patch) | |
tree | efde31dcdedd5c8e2d264300fd40b60ee97c42a4 /src/util.rs | |
parent | fa20f1839448f9d5c7ccb9dcbabeb6d0785f6083 (diff) |
refactor: improve drop fn & tests
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) } } } |