feat: works

This commit is contained in:
2023-10-22 11:38:53 +08:00
parent 1e5a5516bb
commit 4e29789792
8 changed files with 149 additions and 27 deletions

View File

@@ -8,6 +8,7 @@
use std::mem;
use std::slice;
#[allow(clippy::missing_safety_doc)]
pub unsafe trait Safe {}
pub trait AsBytes {
@@ -19,6 +20,7 @@ impl<T: Safe> AsBytes for [T] {
#[inline]
fn as_bytes(&self) -> &[u8] {
unsafe {
#[allow(clippy::manual_slice_size_calculation)]
slice::from_raw_parts(self.as_ptr() as *const u8,
self.len() * mem::size_of::<T>())
}
@@ -27,6 +29,7 @@ impl<T: Safe> AsBytes for [T] {
#[inline]
fn as_mut_bytes(&mut self) -> &mut [u8] {
unsafe {
#[allow(clippy::manual_slice_size_calculation)]
slice::from_raw_parts_mut(self.as_mut_ptr() as *mut u8,
self.len() * mem::size_of::<T>())
}