1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use bevy_ecs::prelude::*;
use derive_more::Deref;
use uuid::Uuid;

/// The universally unique identifier of an entity. Component wrapper for a
/// [`Uuid`].
///
/// This component is expected to remain _unique_ and _constant_ during the
/// lifetime of the entity. The [`Default`] impl generates a new random UUID.
#[derive(Component, Copy, Clone, PartialEq, Eq, Debug, PartialOrd, Ord, Hash, Deref)]
pub struct UniqueId(pub Uuid);

/// Generates a new random UUID.
impl Default for UniqueId {
    fn default() -> Self {
        Self(Uuid::from_bytes(rand::random()))
    }
}