Created
March 14, 2018 02:05
-
-
Save rust-play/01b796a733f4a7ac4000de06af275f25 to your computer and use it in GitHub Desktop.
Code shared from the Rust 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
#![feature(ptr_internals)] | |
use std::ptr::Unique; | |
fn main() { | |
let mut arr = [1u8, 2, 3]; | |
let slice = &mut arr[..]; | |
let unique : Unique<[u8]> = Unique::new(slice as *mut [u8]).unwrap(); | |
// Cast unique to an usize | |
let ptr = unsafe { (&(*unique.as_ptr())[0] as *const u8 as usize) }; | |
println!("{:?} {:x}", unique, ptr); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment