Implement logging purely in Rust

This commit is contained in:
topjohnwu
2023-05-09 18:54:38 -07:00
parent 8c2ad3883a
commit 7518092ad2
17 changed files with 433 additions and 228 deletions

View File

@@ -151,3 +151,24 @@ pub unsafe fn slice_from_ptr_mut<'a, T>(buf: *mut T, len: usize) -> &'a mut [T]
slice::from_raw_parts_mut(buf, len)
}
}
pub trait FlatData {
fn as_raw_bytes(&self) -> &[u8]
where
Self: Sized,
{
unsafe {
let self_ptr = self as *const Self as *const u8;
slice::from_raw_parts(self_ptr, std::mem::size_of::<Self>())
}
}
fn as_raw_bytes_mut(&mut self) -> &mut [u8]
where
Self: Sized,
{
unsafe {
let self_ptr = self as *mut Self as *mut u8;
slice::from_raw_parts_mut(self_ptr, std::mem::size_of::<Self>())
}
}
}