blob: 5d402b37386ecf40a8f257e8b2ca27e6b3f1f358 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
use core::slice;
use core::mem::size_of;
pub trait AsBytes: Sized {
fn as_bytes(&self) -> &[u8] {
unsafe { slice::from_raw_parts(self as *const _ as *const u8, size_of::<Self>()) }
}
}
impl AsBytes for u128 {}
impl AsBytes for u64 {}
impl AsBytes for u32 {}
impl AsBytes for u16 {}
impl AsBytes for u8 {}
|