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. `serde` adds `Secret` deserialization without
20//! implementing `Serialize`; `serde_with` includes `serde` and adds the explicit
21//! `ExposeSecret` output adapter. Output is plaintext, not encryption; see `Secret`
22//! for error-redaction and zeroization boundaries.
23//!
24//! Validation returns an application-defined error; construction
25//! uses `try_new` rather than the removed `TryFrom` implementation.
26//!
27//! **日本語:**<br>
28//! `ddd-toolkit-core` 0.4 のトレイトとヘルパーを再公開します。
29//! [`Entity`]、[`ValueObject`]、[`AggregateRoot`]、[`Repository`]、
30//! [`AsyncRepository`]、イベント発行、CQRS、イベントソーシングの契約を含みます。
31//! ストレージのアダプターと非同期ランタイムはアプリケーションが提供します。
32//!
33//! 既定の `derive` feature では `ValueObject`、`Entity`、`DomainEvent`、
34//! `AggregateRoot` の derive マクロもルートから利用できます。生成パスは直接依存の
35//! `ddd-toolkit-core` を優先し、なければファサードを使います。両者の依存名変更に
36//! 対応しており、ファサードだけの依存でも利用できます。
37//!
38//! 任意の `serde` feature はコアの serde 対応と生成された逆直列化に必要な serde の
39//! derive を有効にします。直列化は型ごとに `#[value_object(serde)]` で指定し、
40//! 他のオプションと併用するときはこのフラグを最後に置きます。単一フィールドの
41//! タプル型 enum variant は newtype 形式で、`Code(7)` は `{"Code":7}` を出力します。
42//! マクロ 0.5 では旧出力 `{"Code":[7]}` から変わるため、保存済みの対象バリアントの
43//! 外側のタプルラッパーを除去してから読み込んでください。全 derive に直列化が
44//! 自動適用されるわけではありません。
45//! [`Secret`] は feature 指定なしで使え、書式出力を秘匿化して破棄時に内容をゼロ化します。
46//! `serde` では `Serialize` を実装せずに復元に対応します。`serde_with` は `serde` を含み、
47//! 明示的な出力用の `ExposeSecret` を追加します。出力は暗号化されない平文です。
48//! エラー秘匿とゼロ化の範囲は `Secret` の説明を参照してください。
49//!
50//! 検証はアプリケーション定義のエラーを返します。廃止された
51//! `TryFrom` 実装の代わりに `try_new` で構築します。
52//!
53//! # Example / 使用例
54//!
55//! ```rust
56//! # #[cfg(feature = "derive")] {
57//! #[derive(ddd_toolkit::ValueObject)]
58//! #[value_object(validate = validate_email, error = &'static str)]
59//! struct Email(String);
60//!
61//! fn validate_email(value: &str) -> Result<(), &'static str> {
62//!     if value.contains('@') { Ok(()) } else { Err("missing @") }
63//! }
64//!
65//! let email = Email::try_new("a@b.com".to_owned()).unwrap();
66//! assert_eq!(email.as_inner(), "a@b.com");
67//! assert_eq!(Email::try_new("invalid".to_owned()), Err("missing @"));
68//! # }
69//! let key = ddd_toolkit::Secret::new("sekret".to_owned());
70//! assert_eq!(format!("{key:?}"), "[REDACTED]");
71//! assert_eq!(key.expose_secret(|value| value.len()), 6);
72//! ```
73
74extern crate self as ddd_toolkit;
75
76pub use ddd_toolkit_core::*;
77
78#[cfg(feature = "derive")]
79pub use ddd_toolkit_macro::*;