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
/// Trait for representing a **Value Object**.
///
/// > There are cases when we need to contain some attributes of a domain element. We are not
/// > interested in which object it is, but what attributes it has. An object that is used to
/// > describe certain aspects of a domain, and which does not have identity, is named Value Object.
///
/// # Examples
///
/// Derive its implementation using the [ddd_rs::ValueObject](crate::ValueObject) macro:
///
/// ```
/// // Annotate the equality components with the `#[value_object(eq)]` attribute.
/// #[derive(ddd_rs::ValueObject, Debug)]
/// struct MyValueObject {
/// #[value_object(eq)]
/// x: bool,
/// y: Option<i32>,
/// #[value_object(eq)]
/// z: String,
/// }
///
/// let a = MyValueObject { x: true, y: Some(42), z: String::from("foo") };
/// let b = MyValueObject { x: true, y: Some(-1), z: String::from("foo") };
/// let c = MyValueObject { x: false, y: Some(42), z: String::from("bar") };
///
/// // `ValueObject`s are equal if all their equality components are equal.
/// assert_eq!(a, b);
/// assert_ne!(a, c);
///
/// // They are also cloneable, by definition.
/// let a_clone = a.clone();
///
/// assert_eq!(a.x, a_clone.x);
/// assert_eq!(a.y, a_clone.y);
/// assert_eq!(a.z, a_clone.z);
/// ```