MCPcopy Create free account
hub / github.com/Apress/beginning-rust-2e / as_bytes

Function as_bytes

Source Code/12-07.rs:11–17  ·  view source on GitHub ↗
(o: &T)

Source from the content-addressed store, hash-verified

9*/
10fn main() {
11 fn as_bytes<T>(o: &T) -> &[u8] {
12 unsafe {
13 std::slice::from_raw_parts(
14 o as *const _ as *const u8,
15 std::mem::size_of::<T>())
16 }
17 }
18 println!("{:?}", as_bytes(&1i8));
19 println!("{:?}", as_bytes(&2i16));
20 println!("{:?}", as_bytes(&3i32));

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected