Created
October 23, 2017 04:28
-
-
Save anonymous/c5f01a1f438bee9e8e877430d6631972 to your computer and use it in GitHub Desktop.
Rust code shared from the playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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