Function safe_transmute::guarded_transmute_to_bytes
source · pub unsafe fn guarded_transmute_to_bytes<T>(from: &T) -> &[u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
Expand description
Transmute a single instance of an arbitrary type into a slice of its bytes.
Examples
An u32
:
assert_eq!(guarded_transmute_to_bytes(&0x01234567),
&[0x67, 0x45, 0x23, 0x01]);
An arbitrary type:
#[repr(C)]
struct Gene {
x1: u8,
x2: u8,
}
assert_eq!(guarded_transmute_to_bytes(&Gene {
x1: 0x42,
x2: 0x69,
}),
&[0x42, 0x69]);