eventide-macros
中文版本: README.zh.md
Procedural macros that generate the boilerplate around the
eventide DDD/CQRS toolkit:
#[entity], #[entity_id], #[domain_event], #[value_object].
Generated code uses the absolute path
::eventide_domain::.... The companion crateeventide-domaindeclaresextern crate self as eventide_domain;so the macros also resolve inside its own tests and examples.
Default derives
The macros merge user-supplied derives with sensible defaults so you rarely have to repeat the same list:
| Macro | Auto-applied derives |
|---|---|
#[entity] |
Debug*, Default, serde::Serialize, serde::Deserialize |
#[entity_id] |
Default, Clone, Debug*, serde::Serialize, serde::Deserialize, PartialEq, Eq, Hash |
#[domain_event] |
Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize |
#[value_object] |
Default, Clone, Debug*, serde::Serialize, serde::Deserialize, PartialEq, Eq |
* = can be turned off with debug = false.
Make sure serde is in your dependency tree with the derive feature:
[]
= { = "1", = ["derive"] }
#[entity]
Apply to a named-field struct. The macro:
- Adds
id: IdTypeandversion: usizeif missing, ordered first. - Implements
Entitywithnew/id/version. - Merges in the default derives (deduplicated).
// id type defaults to String when omitted
// opt out of automatic Debug derive
Restrictions: named-field struct only.
#[entity_id]
Apply to a single-field tuple struct (e.g. struct AccountId(String);). The
macro:
- Implements
FromStr(delegated to the inner type) andDisplay. - Provides
pub fn new(value: Inner) -> Self. - Adds bidirectional conversions (
AsRef,AsMut,From<&Self> for Inner, etc.). - Merges in the default derives.
;
Restrictions: tuple struct with exactly one field.
#[domain_event]
Apply to an enum whose variants use named fields. The macro:
- Adds
id: IdTypeandaggregate_version: usizeto each variant if missing. - Implements
DomainEvent. - Sets the event type to
EnumName.Variantby default; override per variant. - Sets the event version from the enum-level
versionargument; override per variant.
Per-variant overrides are written as
#[event(event_type = "...", event_version = N)].
#[value_object]
Apply to a struct (named-field or tuple) or an enum. The macro merges in the default derives without changing the existing fields/variants.
;
If the target is an enum and Default is enabled (the default), one
variant must be marked with #[default].
UI tests
The crate uses trybuild to verify
that the generated code compiles for representative inputs. Test cases
live under tests/ui/.
Layered architecture
eventide-application → eventide-domain ← eventide-macros
eventide-macros only emits domain-layer items, keeping infrastructure
concerns out of generated code.
License
Licensed under either of Apache-2.0 or MIT at your option.