ddd_toolkit_core/lib.rs
1//! Traits and reference implementations for Domain-Driven Design building
2//! blocks: entities, value objects, aggregates, repositories, and event
3//! dispatch.
4//!
5//! - [`domain`] - the domain-layer traits: [`domain::Entity`],
6//! [`domain::AggregateRoot`], [`domain::ValueObject`]/[`domain::Wrapped`],
7//! [`domain::EntityId`], [`domain::SecretVo`], [`domain::EnumVo`],
8//! [`domain::DomainEvent`].
9//! - [`port`] - the ports a domain depends on: repository (`Load`/`Save`/
10//! `Delete`), [`port::event::EventDispatcher`], [`port::clock::Clock`],
11//! [`port::id::IdGenerator`].
12//! - [`adapter`] - real adapters for those ports (behind the `chrono`/`uuid`
13//! features).
14//! - [`mock`] - in-memory/fixed adapters, useful as test doubles or a
15//! starting point for a real backend.
16//! - [`application`] - [`application::usecase::UseCase`].
17//!
18//! Pair this crate with
19//! [`ddd-toolkit-macro`](https://docs.rs/ddd-toolkit-macro) for
20//! `#[derive(...)]` support on the value-object-shaped traits, or depend on
21//! [`ddd-toolkit`](https://docs.rs/ddd-toolkit) to get both behind a single
22//! dependency.
23//!
24//! # Example
25//!
26//! ```
27//! use ddd_toolkit_core::domain::{Entity, EntityId, ValueObject};
28//! use std::fmt::Display;
29//!
30//! #[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
31//! struct OrderId(String);
32//!
33//! impl ValueObject for OrderId {}
34//!
35//! impl Display for OrderId {
36//! fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37//! write!(f, "{}", self.0)
38//! }
39//! }
40//!
41//! impl EntityId for OrderId {}
42//!
43//! struct Order {
44//! id: OrderId,
45//! }
46//!
47//! impl Entity for Order {
48//! type Id = OrderId;
49//!
50//! fn id(&self) -> &Self::Id {
51//! &self.id
52//! }
53//! }
54//!
55//! let a = Order { id: OrderId("order-1".to_string()) };
56//! let b = Order { id: OrderId("order-1".to_string()) };
57//! assert!(a.is_same_as(&b)); // identity, not structural equality
58//! ```
59
60pub mod adapter;
61pub mod application;
62pub mod domain;
63pub mod mock;
64pub mod port;
65
66#[cfg(test)]
67mod testing;