[][src]Macro my_own_uuid::my_own_uuid

macro_rules! my_own_uuid {
    ($(#[$meta:meta])* $this_val:ident) => { ... };
}

Make your own Uuid.

We might use this to differentiate between two different identifiers:

// we have an entity id...
my_own_uuid!(EntityId);

// and we have an asset id...
my_own_uuid!(AssetId);

// an example struct...
struct Entity {
    id: EntityId,
    sprite: AssetId,
}

let my_new_entity = Entity {
    id: EntityId::new(),
    sprite: AssetId::new()
};

// you'd get this from some sort of database in real code.
let my_other_asset = AssetId::new();

// this line won't compile because of the newtype wrapper!
// if my_new_entity.id == my_other_asset {

// but this line WILL compile!
if my_new_entity.sprite == my_other_asset {
    // explode, we had a Uuid collision, contact the UN, the impossible happened.
    // but actually you probably got this from a database, rather than
    // constructed them inline.
}

Important note here: you can document your own Uuid like so:

my_own_uuid!(
    /// An EntityId is a very good id. It's honestly
    /// my *favorite* id. Don't tell the other ids.
    EntityId
);

The above will show up in docs and in most IDEs when you hover over an EntityId!