ddd_rs_derive/
lib.rs

1//! # ddd-rs-derive
2//!
3//! `ddd-rs`'s proc macros.
4
5#![warn(missing_docs)]
6
7mod aggregate_root;
8mod entity;
9mod value_object;
10
11use proc_macro::TokenStream;
12
13/// Proc macro for deriving the `AggregateRoot` trait.
14///
15/// Use the `#[aggregate_root(domain_events)]` attribute to tag the domain events field of the
16/// aggregate root, which is assumed to be a `Vec`.
17#[proc_macro_derive(AggregateRoot, attributes(aggregate_root))]
18pub fn derive_aggregate_root(input: TokenStream) -> TokenStream {
19    aggregate_root::derive(input)
20}
21
22/// Proc macro for deriving the `Entity` trait.
23///
24/// Use the `#[entity(id)]` attribute to tag the identity (ID) field of the entity.
25#[proc_macro_derive(Entity, attributes(entity))]
26pub fn derive_entity(input: TokenStream) -> TokenStream {
27    entity::derive(input)
28}
29
30/// Proc macro for deriving the `ValueObject` trait.
31///
32/// Use the `#[value_object(eq)]` attribute to tag which fields should be considered as equality
33/// components when comparing value objects.
34#[proc_macro_derive(ValueObject, attributes(value_object))]
35pub fn derive_value_object(input: TokenStream) -> TokenStream {
36    value_object::derive(input)
37}