hexser_macros/lib.rs
1//! Procedural macros for the hex crate.
2//!
3//! This crate provides derive macros that enable zero-boilerplate hexagonal architecture
4//! by automatically implementing registration traits and generating metadata for
5//! compile-time graph construction.
6//!
7//! # Derive Macros
8//!
9//! - `#[derive(HexDomain)]` - Register a domain-layer type (role defaults to `Entity`;
10//! override with `#[hex(role = "ValueObject")]`)
11//! - `#[derive(HexPort)]` - Register a port-layer type (role defaults to `Repository`;
12//! override with `#[hex(role = "InputPort")]`)
13//! - `#[derive(HexAdapter)]` - Register an adapter and mark it as an `Adapter`
14//! - `#[derive(HexEntity)]` - Implement `HexEntity`, taking `Id` from the `id` field
15//! - `#[derive(HexValueItem)]` - Implement `HexValueItem` with default validation
16//! - `#[derive(HexAggregate)]` - Implement `Aggregate` with default invariant check
17//! - `#[derive(HexDirective)]` - Implement `Directive` and register (role `Directive`;
18//! override with `#[hex(role = "...")]`)
19//! - `#[derive(HexQuery)]` - Register a query type (role `Query`; override with
20//! `#[hex(role = "UseCase")]` for a registration-only Application-layer marker)
21//! - `#[derive(HexRepository)]` - Semantic marker for repository ports (pair with `HexPort`)
22//!
23//! # Example
24//!
25//! ```rust,ignore
26//! use hexser::prelude::*;
27//!
28//! #[derive(HexDomain, HexEntity)]
29//! struct User {
30//! id: String,
31//! email: String,
32//! }
33//! ```
34//!
35//! Revision History
36//! - 2026-09-04T00:00:00Z @AI: All five registration derives honour `#[hex(role)]` (HexDomain
37//! declared the attribute and ignored it; HexDirective/HexQuery did not declare it at all), and
38//! a registration derive on a generic type is now a compile error instead of a silent omission.
39//! - 2026-07-20T00:00:00Z @AI: Remove unexported/unused/non-functional error macros and their dead codegen; refresh docs to match the shipped derive set.
40//! - 2025-10-09T14:14:00Z @AI: Remove Entity derive, expose only HexEntity for clarity.
41//! - 2025-10-06T02:00:00Z @AI: Add error construction macros.
42//! - 2025-10-02T00:00:00Z @AI: Initial Phase 3 proc macro crate.
43
44mod common;
45mod derive;
46
47#[proc_macro_derive(HexDomain, attributes(hex))]
48pub fn derive_hex_domain(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
49 crate::derive::hex_domain::derive(input)
50}
51
52#[proc_macro_derive(HexPort, attributes(hex))]
53pub fn derive_hex_port(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
54 crate::derive::hex_port::derive(input)
55}
56
57#[proc_macro_derive(HexAdapter, attributes(hex))]
58pub fn derive_hex_adapter(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
59 crate::derive::hex_adapter::derive(input)
60}
61
62#[proc_macro_derive(HexAggregate, attributes(hex))]
63pub fn derive_hex_aggregate(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
64 crate::derive::aggregate::derive(input)
65}
66
67#[proc_macro_derive(HexEntity)]
68pub fn derive_hex_entity(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
69 crate::derive::entity::derive(input)
70}
71
72#[proc_macro_derive(HexValueItem)]
73pub fn derive_hex_value_item(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
74 crate::derive::hex_value_item::derive(input)
75}
76
77#[proc_macro_derive(HexRepository)]
78pub fn derive_repository(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
79 crate::derive::repository::derive(input)
80}
81
82#[proc_macro_derive(HexDirective, attributes(hex))]
83pub fn derive_directive(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
84 crate::derive::directive::derive(input)
85}
86
87#[proc_macro_derive(HexQuery, attributes(hex))]
88pub fn derive_query(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
89 crate::derive::query::derive(input)
90}