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. Also includes error construction macros with
6//! automatic source location capture.
7//!
8//! # Derive Macros
9//!
10//! - `#[derive(HexDomain)]` - Mark domain layer types
11//! - `#[derive(HexPort)]` - Mark port traits
12//! - `#[derive(HexAdapter)]` - Mark adapter implementations
13//! - `#[derive(Entity)]` - Implement HexEntity trait
14//! - `#[derive(HexValueItem)]` - Implement HexValueItem trait with default validation
15//! - `#[derive(HexAggregate)]` - Mark aggregate roots
16//! - `#[derive(Repository)]` - Mark repository ports
17//!
18//! # Error Macros
19//!
20//! - `hex_domain_error!(code, message)` - Create domain error with source location
21//! - `hex_port_error!(code, message)` - Create port error with source location
22//! - `hex_adapter_error!(code, message)` - Create adapter error with source location
23//!
24//! # Example
25//!
26//! ```rust,ignore
27//! use hexser::prelude::*;
28//!
29//! #[derive(HexDomain, Entity)]
30//! struct User {
31//!     id: String,
32//!     email: String,
33//! }
34//!
35//! let err = hex_domain_error!("E_HEX_001", "Invalid state");
36//! ```
37//!
38//! Revision History
39//! - 2025-10-06T02:00:00Z @AI: Add error construction macros.
40//! - 2025-10-02T00:00:00Z @AI: Initial Phase 3 proc macro crate.
41
42mod common;
43mod derive;
44mod error;
45mod registration;
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(Entity)]
68pub fn derive_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)]
83pub fn derive_directive(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
84  crate::derive::directive::derive(input)
85}
86
87#[proc_macro_derive(HexQuery)]
88pub fn derive_query(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
89  crate::derive::query::derive(input)
90}
91
92#[proc_macro]
93pub fn hex_domain_error(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
94  crate::error::hex_error_macro::hex_domain_error_impl(input)
95}
96
97#[proc_macro]
98pub fn hex_port_error(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
99  crate::error::hex_error_macro::hex_port_error_impl(input)
100}
101
102#[proc_macro]
103pub fn hex_adapter_error(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
104  crate::error::hex_error_macro::hex_adapter_error_impl(input)
105}