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//! Macro 0.4 requires consumers to add `ddd-toolkit-core = "0.4.0"` directly,
10//! even when invoking derives through this facade. Trait-only usage does not.
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//! In macro 0.4.0, single-field tuple enum variants cannot round-trip their own
16//! JSON; use named variants instead. [`Secret`] requires no feature and redacts
17//! formatting and zeroizes its contents on drop without a feature flag.
18//!
19//! Validation returns an application-defined error; construction
20//! uses `try_new` rather than the removed `TryFrom` implementation.
21//!
22//! **日本語:**<br>
23//! `ddd-toolkit-core` 0.4 のトレイトとヘルパーを再公開します。
24//! [`Entity`]、[`ValueObject`]、[`AggregateRoot`]、[`Repository`]、
25//! [`AsyncRepository`]、イベント発行、CQRS、イベントソーシングの契約を含みます。
26//! ストレージのアダプターと非同期ランタイムはアプリケーションが提供します。
27//!
28//! 既定の `derive` feature では `ValueObject`、`Entity`、`DomainEvent`、
29//! `AggregateRoot` の derive マクロもルートから利用できます。マクロ 0.4 は
30//! ファサード経由でも利用側に `ddd-toolkit-core = "0.4.0"` の直接依存を要求します。
31//! トレイトだけを使用する場合、直接依存は不要です。
32//!
33//! 任意の `serde` feature はコアの serde 対応と生成された逆直列化に必要な serde の
34//! derive を有効にします。直列化は型ごとに `#[value_object(serde)]` で指定し、
35//! 他のオプションと併用するときはこのフラグを最後に置きます。マクロ 0.4.0 では
36//! 1フィールドのタプル型 enum variant は自身の JSON 出力を逆変換できないため、
37//! 名前付き variant を使ってください。全 derive に直列化が自動適用されるわけではありません。
38//! [`Secret`] は feature 指定なしで使え、書式出力を秘匿化して破棄時に内容をゼロ化します。
39//!
40//! 検証はアプリケーション定義のエラーを返します。廃止された
41//! `TryFrom` 実装の代わりに `try_new` で構築します。
42//!
43//! # Example / 使用例
44//!
45//! ```rust
46//! # #[cfg(feature = "derive")] {
47//! #[derive(ddd_toolkit::ValueObject)]
48//! #[value_object(validate = validate_email, error = &'static str)]
49//! struct Email(String);
50//!
51//! fn validate_email(value: &str) -> Result<(), &'static str> {
52//! if value.contains('@') { Ok(()) } else { Err("missing @") }
53//! }
54//!
55//! let email = Email::try_new("a@b.com".to_owned()).unwrap();
56//! assert_eq!(email.as_inner(), "a@b.com");
57//! assert_eq!(Email::try_new("invalid".to_owned()), Err("missing @"));
58//! # }
59//! let key = ddd_toolkit::Secret::new("sekret".to_owned());
60//! assert_eq!(format!("{key:?}"), "[REDACTED]");
61//! assert_eq!(key.expose_secret(|value| value.len()), 6);
62//! ```
63
64pub use ddd_toolkit_core::*;
65
66#[cfg(feature = "derive")]
67pub use ddd_toolkit_macro::*;