Skip to content

Instantly share code, notes, and snippets.

Created October 23, 2017 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/c5f01a1f438bee9e8e877430d6631972 to your computer and use it in GitHub Desktop.
Save anonymous/c5f01a1f438bee9e8e877430d6631972 to your computer and use it in GitHub Desktop.
Rust code shared from the playground
use std::slice;
use std::mem;
fn main() {
outer_type(&0x01020304u32);
}
fn outer_type<T>(v: *const T)
where
T: Sized,
{
let size: usize = mem::size_of::<T>();
let slice: &[u8] = unsafe { slice::from_raw_parts(v as *const u8, size) };
println!("{:?}", slice);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment