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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! Traits and reference implementations for Domain-Driven Design building
//! blocks: entities, value objects, aggregates, repositories, and event
//! dispatch.
//!
//! - [`domain`] - the domain-layer traits: [`domain::Entity`],
//! [`domain::AggregateRoot`], [`domain::ValueObject`]/[`domain::Wrapped`],
//! [`domain::EntityId`], [`domain::SecretVo`], [`domain::EnumVo`],
//! [`domain::DomainEvent`].
//! - [`port`] - the ports a domain depends on: repository (`Load`/`Save`/
//! `Delete`), [`port::event::EventDispatcher`], [`port::clock::Clock`],
//! [`port::id::IdGenerator`].
//! - [`adapter`] - real adapters for those ports (behind the `chrono`/`uuid`
//! features).
//! - [`mock`] - in-memory/fixed adapters, useful as test doubles or a
//! starting point for a real backend.
//! - [`application`] - [`application::usecase::UseCase`].
//!
//! Pair this crate with
//! [`ddd-toolkit-macro`](https://docs.rs/ddd-toolkit-macro) for
//! `#[derive(...)]` support on the value-object-shaped traits, or depend on
//! [`ddd-toolkit`](https://docs.rs/ddd-toolkit) to get both behind a single
//! dependency.
//!
//! # Example
//!
//! ```
//! use ddd_toolkit_core::domain::{Entity, EntityId, ValueObject};
//! use std::fmt::Display;
//!
//! #[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
//! struct OrderId(String);
//!
//! impl ValueObject for OrderId {}
//!
//! impl Display for OrderId {
//! fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
//! write!(f, "{}", self.0)
//! }
//! }
//!
//! impl EntityId for OrderId {}
//!
//! struct Order {
//! id: OrderId,
//! }
//!
//! impl Entity for Order {
//! type Id = OrderId;
//!
//! fn id(&self) -> &Self::Id {
//! &self.id
//! }
//! }
//!
//! let a = Order { id: OrderId("order-1".to_string()) };
//! let b = Order { id: OrderId("order-1".to_string()) };
//! assert!(a.is_same_as(&b)); // identity, not structural equality
//! ```
/// The domain layer: entities, value objects, aggregates, and events.