Skip to main content

ddd_toolkit/
lib.rs

1//! **English:**<br>
2//! Re-exports the traits and helpers from `ddd-toolkit-core` 0.4,
3//! including [`Entity`], [`ValueObject`], [`AggregateRoot`], [`Repository`],
4//! [`AsyncRepository`], event publishing, CQRS, and event-sourcing contracts.
5//! Storage adapters and async runtimes are supplied by the application.
6//!
7//! With the default `derive` feature, the `ValueObject`, `Entity`, `DomainEvent`,
8//! and `AggregateRoot` derive macros are also available at this crate's root.
9//! Generated paths prefer a direct `ddd-toolkit-core` dependency, then this
10//! facade. Both dependencies may be renamed; a facade-only dependency suffices.
11//!
12//! The optional `serde` feature enables core's serde support and the serde
13//! derives needed by generated deserializers. Serialization is opt-in per value
14//! object with `#[value_object(serde)]`; put this flag last when combining options.
15//! Single-field tuple enum variants use Serde's newtype format: `Code(7)` emits
16//! `{"Code":7}`. Macro 0.5 changes the old `{"Code":[7]}` output; migrate saved
17//! data by removing its outer tuple wrapper for affected variants before loading.
18//! [`Secret`] requires no feature and redacts formatting and zeroizes its contents
19//! on drop without a feature flag.
20//!
21//! Validation returns an application-defined error; construction
22//! uses `try_new` rather than the removed `TryFrom` implementation.
23//!
24//! **日本語:**<br>
25//! `ddd-toolkit-core` 0.4 のトレイトとヘルパーを再公開します。
26//! [`Entity`]、[`ValueObject`]、[`AggregateRoot`]、[`Repository`]、
27//! [`AsyncRepository`]、イベント発行、CQRS、イベントソーシングの契約を含みます。
28//! ストレージのアダプターと非同期ランタイムはアプリケーションが提供します。
29//!
30//! 既定の `derive` feature では `ValueObject`、`Entity`、`DomainEvent`、
31//! `AggregateRoot` の derive マクロもルートから利用できます。生成パスは直接依存の
32//! `ddd-toolkit-core` を優先し、なければファサードを使います。両者の依存名変更に
33//! 対応しており、ファサードだけの依存でも利用できます。
34//!
35//! 任意の `serde` feature はコアの serde 対応と生成された逆直列化に必要な serde の
36//! derive を有効にします。直列化は型ごとに `#[value_object(serde)]` で指定し、
37//! 他のオプションと併用するときはこのフラグを最後に置きます。単一フィールドの
38//! タプル型 enum variant は newtype 形式で、`Code(7)` は `{"Code":7}` を出力します。
39//! マクロ 0.5 では旧出力 `{"Code":[7]}` から変わるため、保存済みの対象バリアントの
40//! 外側のタプルラッパーを除去してから読み込んでください。全 derive に直列化が
41//! 自動適用されるわけではありません。
42//! [`Secret`] は feature 指定なしで使え、書式出力を秘匿化して破棄時に内容をゼロ化します。
43//!
44//! 検証はアプリケーション定義のエラーを返します。廃止された
45//! `TryFrom` 実装の代わりに `try_new` で構築します。
46//!
47//! # Example / 使用例
48//!
49//! ```rust
50//! # #[cfg(feature = "derive")] {
51//! #[derive(ddd_toolkit::ValueObject)]
52//! #[value_object(validate = validate_email, error = &'static str)]
53//! struct Email(String);
54//!
55//! fn validate_email(value: &str) -> Result<(), &'static str> {
56//!     if value.contains('@') { Ok(()) } else { Err("missing @") }
57//! }
58//!
59//! let email = Email::try_new("a@b.com".to_owned()).unwrap();
60//! assert_eq!(email.as_inner(), "a@b.com");
61//! assert_eq!(Email::try_new("invalid".to_owned()), Err("missing @"));
62//! # }
63//! let key = ddd_toolkit::Secret::new("sekret".to_owned());
64//! assert_eq!(format!("{key:?}"), "[REDACTED]");
65//! assert_eq!(key.expose_secret(|value| value.len()), 6);
66//! ```
67
68extern crate self as ddd_toolkit;
69
70pub use ddd_toolkit_core::*;
71
72#[cfg(feature = "derive")]
73pub use ddd_toolkit_macro::*;