SHARE
TWEET

Untitled

a guest Jul 17th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use std::ptr;
  2. use std::mem;
  3.  
  4. fn main() {
  5.     let n: i32 = 394;
  6.    
  7.     let a_ptr: *const i32 = &n as *const i32;
  8.     let b_ptr: *const i32 = ptr::null();
  9.    
  10.     let a_opt: Option<&i32> = unsafe { mem::transmute(a_ptr) };
  11.     let b_opt: Option<&i32> = unsafe { mem::transmute(b_ptr) };
  12.    
  13.     assert_eq!(a_opt, Some(&394));
  14.     assert_eq!(b_opt, None);
  15. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top