the.bay.news

How to generate a static and unique ID at compile time?

The Rust Programming Language Forum
How to generate a static and unique ID at compile time?
I want to implement a static unique ID generator, usage like this: // These two are guaranteed to have different values. const UNIQUE_ID_1: u64 = unique!(); const UNIQUE_ID_2: u64 = unique!(); The only solution I found is using TypeId, but it is not u64, and seems not elegant. // These two are guaranteed to have different values. const UNIQUE_ID_1: TypeId = { struct _Unique; TypeId::of::<_Unique>() }; const UNIQUE_ID_2: u64 = { struct _Unique; TypeId::of::<_Unique>() }; Is th...

0 comments

Sign in to join the discussion — your thebay.events account works here.

No comments yet.