ddd_toolkit/lib.rs
1//! Domain-Driven Design building blocks for Rust: entities, value objects,
2//! aggregates, repositories, and event dispatch, plus derive macros for the
3//! common cases. A single-dependency facade re-exporting
4//! [`ddd-toolkit-core`](https://docs.rs/ddd-toolkit-core) and, behind the
5//! `derive` feature (on by default),
6//! [`ddd-toolkit-macro`](https://docs.rs/ddd-toolkit-macro). See this
7//! crate's README for a full example.
8//!
9//! # Example
10//!
11//! ```
12//! use ddd_toolkit::domain::{SecretVo, ValidationError, Wrapped};
13//!
14//! #[derive(ddd_toolkit::ValueObject, Clone, PartialEq, Debug)]
15//! #[vo(validate = "validate_email")]
16//! struct Email(String);
17//!
18//! fn validate_email(s: &str) -> Result<(), ValidationError> {
19//! if s.contains('@') {
20//! Ok(())
21//! } else {
22//! Err(ValidationError::new("Email", "missing @"))
23//! }
24//! }
25//!
26//! #[derive(ddd_toolkit::SecretVo, Clone, PartialEq)]
27//! struct ApiKey(String);
28//!
29//! let email = Email::try_from("a@b.com".to_string()).unwrap();
30//! assert_eq!(email.as_inner(), "a@b.com");
31//!
32//! let key = ApiKey::try_new("sekret".to_string()).unwrap();
33//! assert_eq!(format!("{key:?}"), "ApiKey(***)"); // never leaks the secret
34//! ```
35
36pub use ddd_toolkit_core::*;
37
38#[cfg(feature = "derive")]
39pub use ddd_toolkit_macro::*;