Created
June 18, 2018 15:57
-
-
Save sopvop/01d413b4fcbd05b764b82d523d62a031 to your computer and use it in GitHub Desktop.
unique global id at compile time
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
#[derive(PartialEq, PartialOrd, Debug, Clone, Copy)] | |
pub struct UniqueId(pub u64); | |
macro_rules! unique { | |
() => {{ | |
#[allow(missing_copy_implementations)] | |
#[allow(non_camel_case_types)] | |
#[allow(dead_code)] | |
struct __unique_id_tag {}; | |
use core::any::TypeId; | |
let tid = TypeId::of::<__unique_id_tag>(); | |
unsafe { $crate::debug::UniqueId(*((&tid as *const _) as *const u64)) } | |
}}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment