Skip to content

Instantly share code, notes, and snippets.

@sopvop
Created June 18, 2018 15:57
Show Gist options
  • Save sopvop/01d413b4fcbd05b764b82d523d62a031 to your computer and use it in GitHub Desktop.
Save sopvop/01d413b4fcbd05b764b82d523d62a031 to your computer and use it in GitHub Desktop.
unique global id at compile time
#[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