Created
September 20, 2019 21:38
-
-
Save rust-play/d07a37dc672c6ed66c6e94a75eb1b375 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(core_intrinsics)] | |
use std::intrinsics::discriminant_value; | |
use std::mem::size_of; | |
#[derive(Debug)] | |
#[allow(dead_code)] | |
enum E { | |
A = 0x1000_0000, | |
B = 0, | |
} | |
fn main() { | |
let x = &0xffff_ffffu32 as *const u32 as *const E; | |
let z = unsafe { std::ptr::read(x) }; | |
assert_eq!(size_of::<E>(), size_of::<u32>()); | |
let actual_discriminant = unsafe { discriminant_value(&z) }; | |
println!("{:?}, discriminant 0x{:x}", z, actual_discriminant); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment