Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created March 14, 2018 02:05
Show Gist options
  • Save rust-play/01b796a733f4a7ac4000de06af275f25 to your computer and use it in GitHub Desktop.
Save rust-play/01b796a733f4a7ac4000de06af275f25 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
#![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