1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/// Trait for representing an **Entity**.
///
/// > There is a category of objects which seem to have an identity, which remains the same
/// > throughout the states of the software. For these objects it is not the attributes which
/// > matter, but a thread of continuity and identity, which spans the life of a system and can
/// > extend beyond it. Such objects are called Entities.
///
/// # Examples
///
/// Derive its implementation using the [ddd_rs::Entity](crate::Entity) macro:
///
/// ```
/// use ddd_rs::domain::Entity;
///
/// // Annotate the identity field with the `#[entity(id)]` attribute.
/// #[derive(ddd_rs::Entity, Debug)]
/// struct MyEntity {
/// #[entity(id)]
/// code: u32,
/// my_field: String,
/// }
///
/// impl MyEntity {
/// pub fn new(code: u32, my_field: impl ToString) -> Self {
/// Self {
/// code,
/// my_field: my_field.to_string(),
/// }
/// }
/// }
///
/// let a = MyEntity::new(1, "foo");
/// let b = MyEntity::new(1, "bar");
/// let c = MyEntity::new(2, "foo");
///
/// // By definition, `Entity` equality is based exclusively on their identity.
/// assert_eq!(a, b);
/// assert_eq!(a.id(), b.id());
///
/// assert_ne!(a, c);
/// assert_ne!(a.id(), c.id());
/// ```