atomr_patterns/ddd/entity.rs
1//! [`Entity`] — anything with a stable identity.
2
3use std::hash::Hash;
4
5/// A domain object that is identified by its `Id`, not by its
6/// attribute values. Two `Entity` instances with the same `Id` represent
7/// the same conceptual thing even if their other fields differ.
8pub trait Entity {
9 /// The identity type. Must be hashable so the framework can index
10 /// entities in maps (e.g. inside a [`crate::Repository`]).
11 type Id: Clone + Eq + Hash + Send + Sync + 'static;
12
13 /// Stable identity of this entity instance.
14 fn id(&self) -> &Self::Id;
15}