Skip to content

Instantly share code, notes, and snippets.

@ZhangHanDong
Forked from anonymous/playground.rs
Created October 23, 2017 04:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZhangHanDong/4d73e8baddac4d5703d05101de71a1f1 to your computer and use it in GitHub Desktop.
Save ZhangHanDong/4d73e8baddac4d5703d05101de71a1f1 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